Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

java - Adding background in jButton (netbeans gui builder)

When i try to add background in Jbutton in java by going to its properties and then icon, it then sets the background of the button but the text which i have written on the button,it moves right(outside the button area).What is the solution for this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you wanted to add an Image to your JButton with NetBeans follow these steps :

  1. Right Click Source Packages, under Projects and Select New -> Other -> (Under Categories) Select Other -> (Under File Types) Select Folder.
  2. Click Next, and provide a name to the folder. For Example resources, do check that for Parent Folder, src is written inside the field. Now Click Finish.
  3. Now manually go to this location on your Computer and create a New Folder, say images, and then paste the IMAGE inside this folder.
  4. Now Under Design Mode, select your JButton, and on the Right Side go to this JButton 's properties. Just under foreground you will see icon is written, click the Eclipse Button associated with it to open the window as shown in Figure below : FIGURE 1
  5. Do check, this FIGURE 1, to fill in your values and then Press OK

You are done adding image to your JButton. If you want to use the image I used, here it is Window Image. Yeah, I forgot to mention, for this, I had set horizontalTextPosition = CENTER and veritcalTextPosition = BOTTOM under Other Properties, inside Properties.

And Here is the output of the whole thing :

CELSIUS CONVERTER IMAGE


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...