Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Very Confusing Issue with adding Components  RSS feed

 
Ben Jass
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, I'm working on this small program. Just recently I started working on the GUI aspect of it. I have no idea what's going on, I'm using eclipse and it will randomly add the components correctly and sometimes it won't even add them. So I decided to make it add the panels and the JButtons in the methods that they were declared in. That fixed the issue for the panels and JButtons (I don't know why though). Now for the JComboBox's and the JLabel's. I still don't understand it will randomly work sometimes and sometimes it won't do anything with them. The program does run through every method correctly (I used a logger).

This is about as small as i could make it. IF you import this into your Eclipse (Just get rid of the packaging and add your own main() method). You'll see what I'm talking about.

 
Rob Camick
Ranch Hand
Posts: 2754
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IF you import this into your Eclipse

We don't all use Eclipse or in fact an IDE in general.

add your own main() method


The code you post should be copy and paste which means you should add the main() method so we don't have to.

Without running the code I noticed the following:



Components should be added to the frame BEFORE the frame is made visible. Change the location of the createPanels() method. Also, I believe the setResizable should be done before the setVisible().

Generally you would also use pack() instead of setSize() so all components are displayed at their preferred sizes.
 
Ben Jass
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) I was just giving a recommendation if someone does use eclipse. They could get a better idea.
2) I suppose I guess adding a main() method would make it easier for you guys, just felt a little lazy considering the fact that it's about 3 lines of code. I'll add one next time.

Anyways @TOPIC.

Thanks, It worked.
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there is anything in your code or your question that required use of, understanding of, or even mention of the IDE you are using or that others might use to sample the function of your code. The code should work the same no matter the process to get from *.java to *.class files. Sometimes there's too much focus on the programming process to the exclusion or confusion of the programming fundamentals by both those seeking help and those offering it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!