b_acs
asked on
How do I change the layout of my combo boxes?
I have completed my assignment, but I am not satisfied with the final layout. I would like to move my total box to the right side below my selected boxes. Also, as of right now, if the user wants to select the "default" then they would have to change one of the selections and then change it back. Is there a way to "fix" these things?
you can layout your gui however you want really
http://java.sun.com/docs/books/tutorial/uiswing/layout/
> if the user wants to select the "default" then they would have to change one of the selections and then change it back. Is there a way to "fix" these things?
sound slike you don't initially configure defaults for all components.
setting the combo selection in your code *after* you add your listeners should fix that
http://java.sun.com/docs/books/tutorial/uiswing/layout/
> if the user wants to select the "default" then they would have to change one of the selections and then change it back. Is there a way to "fix" these things?
sound slike you don't initially configure defaults for all components.
setting the combo selection in your code *after* you add your listeners should fix that
ASKER
> setting the combo selection in your code *after* you add your listeners should fix that
I'm sorry to ask, but what do you mean?
I'm sorry to ask, but what do you mean?
why does the user need to change the selection and change it back? whats not getting set?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok I see about setting the defaults, but I think in this case I actually may want an empty default so I also added a new element to the beginning of the arrays that I left blank.
I'm still reading trying to figure out how to move my totalpane to the right side of the box.....
I'm still reading trying to figure out how to move my totalpane to the right side of the box.....
// The following array holds the values that will
// be displayed in the dormBox combo box, including an
// empty line for default initialization.
// Dorm Hall
private String[] dorm = {
"",
"Allen Hall $" + 1500,
"Pike Hall $" + 1600,
"Farthing Hall $" + 1200,
"University Suites $" + 1800
};
// Dorm Rate
double[] drate = {0, 1500, 1600, 1200, 1800};
// The following array holds the values that will
// be displayed in the mealBox combo box, including an
// empty line for default initialization.
//Meal plans
private String[] meal = {
"",
"7 Meals Per Week $" + 560,
"14 meals per week $" + 1095,
"Unlimited meals $" + 1500
};
//Meal plan rate
double [] mrate = {0, 560, 1095, 1500};
as you using a GridLayout for its container you should be able to move it by changing the order you add them (to the parent container). GridLayout fills row by row from left to right
ASKER
But it is the last one added. And I want it to be on the bottom since its the total, but just trying to figure out how to put it on the right. Currently looking at trying to change the formatting on that line to right to left instead of left to right
ASKER
do i need to create a flow layout class to do this?
hard to day without know the exact layout you are trying to achieve
> But it is the last one added. And I want it to be on the bottom since its the total
can still be on the bottom, you just want it in the 1st cell of the bottom row by the sound of it
try adding it 4th
can still be on the bottom, you just want it in the 1st cell of the bottom row by the sound of it
try adding it 4th
ASKER
I'm sorry....my grid is 3 rows by two cols and my preferred setup is:
Dorm Panel Selected Dorm Panel
Meal Panel Selected Meal Panel
Total Panel
So I guess really I want it in the second cell of the bottom row. Currently it is in the first cell
This is obviously a pretty minor issue, (has no impact on my grade....lol) I am just trying to figure out how to get it the way I would like it.....
Dorm Panel Selected Dorm Panel
Meal Panel Selected Meal Panel
Total Panel
So I guess really I want it in the second cell of the bottom row. Currently it is in the first cell
This is obviously a pretty minor issue, (has no impact on my grade....lol) I am just trying to figure out how to get it the way I would like it.....
you could add say an empty JLabel
or use a different layout manager
or use a different layout manager
ASKER
Oh I see....I just read that I will have to use a different layout if I want to leave an empty cell.
Now to figure out which one.....lol
Now to figure out which one.....lol
you could use a 2x1 gridlayout (for the two columns)
and in each column use a (vertical) BoxLayout
and in each column use a (vertical) BoxLayout
ASKER
For simplicity (getting tired...), I did add an empty JPanel and got what I wanted (basically).
I think I will play with this some more to learn how to use some of the different layout managers.
Thank you for your time, objects, I really appreciate it!
I think I will play with this some more to learn how to use some of the different layout managers.
Thank you for your time, objects, I really appreciate it!
ASKER
I'll look into your last suggestion as well
ASKER
Thanks again for your help!
You actually create one column too many in your GridLayout, but to bring over the total panel to where you want it, simply add a blank component before it:
// Add the panels to the content pane.
add(dormPanel);
add(selectedDormPanel);
add(mealPanel);
add(selectedMealPanel);
add(new JLabel(""));
add(totalPanel);
glad I could help, let me know if you need any other help :)
b_acs, i'm a little confused as to how the accepted answer answers your question...
ASKER
CEHJ, I just picked one of objects comments. Honestly I was a little lazy, because I should have split it, but since all of my questions were answered by objects I just picked the first comment of his that answered one of my questions.
That's OK. Anyway, the adjustments i mentioned will fix your main problem
ASKER
Oh and as for the making one column too many, I didn't notice that I hadn't changed that back before posting my code. I was playing with the number of columns and rows trying to see the difference.
Thanks for noticing that...
Thanks for noticing that...
ASKER
Thank you! I did mention that I did what you suggested already. I think I said JPanel instead of JLabel, though. But that's because I actually added an empty panel instead of a blank label. Doing a blank JLabel is a bit simpler though.
ASKER
Open in new window