• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why am I having to using Static on my JComboBox  RSS feed

 
Anthony Johnson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do I have to use static on my JComboBox so that



 
Anthony Johnson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also if I don't have to use static on my JComboBox's, what do I have to do to correct it. If static is the only way to go, I will work with that.
 
Anthony Johnson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also when I launch my program, it opens very small. I have to resize to see everything.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You create a TIineTools in the method 'initializeDatabase' in the 'TLineDatabase' class. Here you add some items to the comboboxes.
Howevder, in the 'main' method in TLineTools you create another TLineTools object, and it is thats frame that you are showing. But in this way you  have not added anything to your comboboxes.
Can you now understand why making the comboboxes static, does indeed show them as they should be?

So, make sure you create only one TLineTools object, that adds to the comboboxes, and show its frame. You do not need to make these comboboxs static anymore.

And also, do a frame.setSize(450, 350) or so to start with a bigger frame.

But better would be to use a decent LayoutManager. Then you do not need to painfully set all the sizes manually.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do I have to use static on my JComboBox

What makes you think you have to use static? Have you tried removing static?
Also when I launch my program, it opens very small. I have to resize to see everything.

You can call the JFrame's setSize() method to set the visible size of the frame. If you were using a LayoutManager (why aren't you?) you could have called the pack() method and the frame would be sized to a size that displays all the components.

BTW There are a number of design issues with your program such as public variables, not using a LayoutManager etc and more seriously creating 2 instances of TLineTools (which means the program won't work as you expect ie the comboxBoxes don't appear to get initialised).

Edit: Doh!! beaten to it by 17 seconds.
 
Anthony Johnson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris wrote:You create a TIineTools in the method 'initializeDatabase' in the 'TLineDatabase' class. Here you add some items to the comboboxes.
Howevder, in the 'main' method in TLineTools you create another TLineTools object, and it is thats frame that you are showing. But in this way you  have not added anything to your comboboxes.
Can you now understand why making the comboboxes static, does indeed show them as they should be?

So, make sure you create only one TLineTools object, that adds to the comboboxes, and show its frame. You do not need to make these comboboxs static anymore.

And also, do a frame.setSize(450, 350) or so to start with a bigger frame.

But better would be to use a decent LayoutManager. Then you do not need to painfully set all the sizes manually.


Sorry I didn't respond sooner, I usually get email alerts. However I will give them all a try now. Thanks
 
Anthony Johnson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:
Why do I have to use static on my JComboBox

What makes you think you have to use static? Have you tried removing static?
Also when I launch my program, it opens very small. I have to resize to see everything.

You can call the JFrame's setSize() method to set the visible size of the frame. If you were using a LayoutManager (why aren't you?) you could have called the pack() method and the frame would be sized to a size that displays all the components.

BTW There are a number of design issues with your program such as public variables, not using a LayoutManager etc and more seriously creating 2 instances of TLineTools (which means the program won't work as you expect ie the comboxBoxes don't appear to get initialised).

Edit: Doh!! beaten to it by 17 seconds.



Also sorry I didn't respond sooner. I will try them all. Thanks
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!