Forums Register Login

hs teacher needs help - display swing components with coordinates

+Pie Number of slices to send: Send
hs teacher needs help -
hi folks,
im a high school teacher teaching a java class for the first time. The students are doing their final projects and I'm coming across some problems.
One student wants to use swing components to display numerous buttons and menus. He wants to know the best way to do this. I decided i need to use jbuttons (right?), and i thought to setlayout to null. As below:
Container c = getContentPane();
c.setLayout(null);
But i cant get menus or scrollpane (scrolling textarea) to work, any simple code to do that...
i and my students appreciate any help you can give
jeff
+Pie Number of slices to send: Send
If you set the content pane to null then you have to use the reshape(xCoor, yCoor, ht, width) class. if you have a JButton next, and a Container box, the code would look something like:
box.add(next);
next.reshape(5,5,100, 25);
this should be what you need, tell me if this helped
GOD Bless
+Pie Number of slices to send: Send
i could get the button to work using .setBounds,
but is that the best way to specify coordinates...
and if so, do you have any code for menus that works with coordinates?
thanks,
jeff
+Pie Number of slices to send: Send
Setting the layout to null causes a lot of problems like this... what was the reason that led you to need to lay out components with specific coordinates? This usually leads to more problems than it solves. There's usually a way to nest layouts, use GridBagLayout, or even create your own layout that will let you achieve what you are trying to do without resorting to null layout.
+Pie Number of slices to send: Send
Simple code for working with null layout? No, not really. Using layout managers makes for simple code.

In the beginning a null layout appears to be an easy choice but as the example below shows it can be quite a chore to get any useful results with it. The one place it seems to work okay is when using mouse code to drag/move components around with.

Once you make friends with and learn to use a few layout managers, say, BorderLayout, FlowLayout, GridLayout and CardLayout, nesting panels opens a whole world of possibilities in putting things together. Later you can get to know more specialized layout managers like BoxLayout and GridBagLayout.
Poop goes in a willow feeder. Wipe with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1097 times.
Similar Threads
Is it a bug of JavaHelp?
Minimum Function
Bumper car program
Swing components in HTML page possible?
Dislay content of List
free 1 hour java lesson
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:41:37.