• Post Reply Bookmark Topic Watch Topic
  • New Topic

Component's showing issues!

 
Ben Jass
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, I'm having issues with this program that I started making. Basically I have a panel (located on the west side), that is going to hold components to alter what is being painted on the right (just the plain frame). I'm having issues with adding the components to the panel. I already have a JComboBox added to it (no issues there), but when I add multiple other components, and it doesn't matter which layout I'm in. I will have to click in the spot at which it is supposed to be located, for it too appear?

I know that sounded rather confusing, but the best way I can explain it is like this: I have a JComboBox and a JSlider, both added to the westPanel. The JComboBox appears when I click run, but there is no JSlider. So I click around in the area where the JSlider should be, and it randomly appears? Also, if I minimize the program, and pop it back up, the JComboBox disappears?

EDIT: I found out that If I take out my paint() method inside my program, that the components appear fine, But when I do have the paint() method, I have these issues. I don't know how to fix this?

Here's the code for it:





 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get rid of the paint() method. You should never override the paint() method of a JFrame.

If you need to do custom painting the read the section from the Swing tutorial on Custom Painting for the proper way to do this.
 
Ben Jass
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks man!
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you ever override paint / paintComponent, always make sure you call the super class' implementation as the first statement:
 
Darryl Burke
Bartender
Posts: 5154
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... except when your custom painting fills the entire area of the component. Even in such cases, I comment a call to the super implementation to remind me that I didn't just forget to include it. Example:
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!