• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hs teacher needs help - display swing components with coordinates

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jeff Borland
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic