3

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

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
Sanshayan
  • 39
  • 1
  • 1
  • 10

3 Answers3

3
  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.

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • how to highlight the JLabel sorry i am new to this – Sanshayan Jan 04 '14 at 04:12
  • Drag a label into the panel and just make sure the label is the one with the blue square, meaning it's highlighted. Just by clicking on it, should highlight it. That makes sure _its_ properties will show up in the properties pane. The properties pane, you should see on the very right of the screen. If it's not open, you should see a tab call properties that you can click on – Paul Samsotha Jan 04 '14 at 04:14
  • In properties there is no icon property.but it have TabIcon – Sanshayan Jan 04 '14 at 04:45
  • It's work only JLabel not for the JPanel thanks for your support – Sanshayan Jan 04 '14 at 05:44
  • JPanel don't use Icons. You need to manually draw the Image with image drawing code, overriding the `paintComponent` method. – Paul Samsotha Jan 04 '14 at 05:46
1
  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
1

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.
Prabhashi
  • 29
  • 5