java - how to add image to JButton -


OK, so I'm reading how to add images to the pocket button using Image Icon, but it still works I'm not doing it, my code is below, I'm using the Eclipse workspace and I think that with the help of the code block below, there is no imported program without importing

  Public Class Gui JFrame Provides {// JPanels Announces JPanel Left = New Zipel (Faucet); JPN = true zeppel (null); Zeppel Topad = New zipal (faucet); JPNL Write + new zipal (faucet); // declaration for right JPYNICAL IMAGIX IMG = New IMAGON ("buttoncon.bmp"); Jebton [] Case = New Payton [26]; Public GUI () {File Image Check = New File ("src / buttonicon.bmp"); If (imageCheck.exists ()) {System.out.println ("found the image file!"); For (int i = 0; i & lt; 26; i ++) {case [i] = new pocket (string.value ((I + 1)); Case [i] .setIcon (new imean ("src / buttonicon.bmp")); }} SetLayout (null); Add (left); (Right) add; Add (TopAd); Add (rightAd); Left Setbound (10, 20, 220, 685); Left.setBackground (Color.black); Right. Setbound (240, 125, 500, 580); Right.setBackground (Color.BLUE); Topad Setbound (240, 20, 635, 95); TopAd.setBackground (Color.darkGray); RightAd.setBounds (750, 125, 125, 580); RightAd.setBackground (Color.GREEN); // Right to right, JPanel (int i = 0; i & lt; 26; i + +) {right.add (case [i]); } Case [0]. Setbound (20, 5, 110, 75); Case [1]. Setbound (135, 5, 110, 75); Case [2]. Setbound (250, 5, 110, 75); Case [3]. Setbound (365, 5, 110, 75); Case [4]. Setbound (20, 85, 110, 75); Case [5]. Setbound (135, 85, 110, 75); Case [6] Setbound (250, 85, 110, 75); Case [7]. Setbound (365, 85, 110, 75); Case [8]. Setbound (20, 165, 110, 75); Case [9]. Setbound (135, 165, 110, 75); Case [10]. Setbound (250, 165, 110, 75); Case [11]. Setbound (365, 165, 110, 75); Case [12]. Setbound (20, 245, 110, 75); Case [13] Setbound (135, 245, 110, 75); Case [14] Setbound (250, 245, 110, 75); Case [15] Setbound (365, 245, 110, 75); Case [16] Setbound (20, 325, 110, 75); Case [17] Setbound (135, 325, 110, 75); Case [18]. Setbound (250, 325, 110, 75); Case [19] Setbound (365, 325, 110, 75); Case [20] Setbound (20, 405, 110, 75); Case [21]. Setbound (135, 405, 110, 75); Case [22]. Setbound (250, 405, 110, 75); Case [23] Setbound (365, 405, 110, 75); Case [24] Setbound (135, 485, 110, 75); Case [25]. Setbound (250, 485, 110, 75);  

}

The problem I'm having

  File image = new file ("src / buttonicon.bmp" ); If (imageCheck.exists ()) {System.out.println ("found the image file!"); For (int i = 0; i & lt; 26; i ++) {case [i] = new pocket (string.value ((I + 1)); Case [i] .setIcon (new imean ("src / buttonicon.bmp")); }}  

I have entered a statement to check whether the file exists or not and it does. No errors have been thrown but the buttons are still living in the default blue color, the same resolution of the button is the same as the image, if anyone helps.

Even if someone can help me in a simple way, it will be extremely fun to set the code and change the tabs with spaces (I use tab instead of spaces

ImageIcon tries to load the image in the background So, if something goes wrong, you do not get the error, it just fails silently and you need to call getImageLoadStatus () New it is to see that the image can be loaded.

I am not sure that BMP is supported by Java instead try PNG pictures.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -