Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Very Confusing Issue with adding Components

 
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.

 
Rancher
Posts: 3139
27
  • 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.
 
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.
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!