Domanda

I have JTabbedPane with five tabs and each have Jpanel i want add different images for each panel in NetBeans IDE

È stato utile?

Soluzione

  1. Right click on your project and add a new package, name it resources. This will need to be done so Netbeans imports your picture into that folder
  2. Add a JLabel to the Panel
  3. Hightlight the JLabel and go to the Properties pane on the right
  4. In the property that says icon click the ... button. That will take you to a dialog
  5. Choose External Image radio button
  6. Click the ... next to the file text field
  7. Pick your Image and click OK.
  8. Click Import to Project
  9. Click OK, You should see the image in your graphic layout

Note this will only give you an Image, but doesn't really act as a background, because the JLabel is it's own component. I'm not really sure how to achieve a backgroud with GUI Builder. I'm not too familiar with the technology. Though if you were to write your own code, there are numerous answers here on SO that I'm sure you'll find useful. The only tricky thing about GUI Builder is that they have auto-generated code that you really can't play around with, which circumvents what I know about creating a background image.

enter image description here

enter image description here

enter image description here


NOTE : this only works for JLabels as JPanels don't use Icon. An alternative would be to hand write your own JPanel code in the constructor and draw the image, overriding the paintComponent method.

Altri suggerimenti

  1. Change the layout of your Jframe to null.
  2. Create a jlabel and cover whole jframe with it.
  3. Add your image to the icon property of the inserted jlabel.
  4. Change the layout of jframe back to free layout. You are done 👍👍 It worked for me

May be you'll find this link useful.

This tutorial shows you how to use the IDE's GUI Builder to generate the code to include images (and other resources) in your application. In addition, you will learn how to customize the way the IDE generates image handling code.

Handling Images in a Java GUI Application

Basically, following are the steps.

  1. Drag a Label to the JFrame
  2. Add a new package (for the image to be stored)
  3. Select Label and go to the Properties category
  4. Select the Icon property and click 'Import to Project...'
  5. Select the image and then the newly created package
  6. In Properties window of Label, select text property and delete it.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top