Archived

This topic is now archived and is closed to further replies.

[java] Locations

This topic is 4941 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For my applet, I have made two TextAreas. One TextArea is on the West side of the screen, while the other is on the East side of the screen. I have also made five buttons, Chat, Actions, PM, Trade, and Battle. I put the five buttons on the South side of the screen. But that is not where I want them. I would like to know how can I have Chat and Actions buttons right below the West side TextArea and the PM, Trade, and Battle right below the East side TextArea. Also I used BorderLayout and FlowLayout. [edited by - DKN on May 30, 2004 6:59:17 PM]

Share this post


Link to post
Share on other sites
bah there are so many methods of doing GridBagLayout that I'm not sure with everything I'm doing. For some reason whenever I make buttons on an applet with GridBagLayout, they either overlap each other, to close to each other, or to far apart. Like with this one applet I'm doing the buttons overlap. Here is the part of my code with the GridBagLayout:

GridBagLayout section = new GridBagLayout();
frame.getContentPane ().setLayout(section);
GridBagConstraints c = new GridBagConstraints();


c.weightx = 1;
c.weighty = 1;
c.gridwidth=5;
c.gridx = 0;
c.gridy = 0;
c.anchor = GridBagConstraints.NORTHWEST;
section.setConstraints(textscroll,c);
frame.getContentPane ().add(textscroll);

c.weightx = 0;
c.weighty = 5;
c.gridx = 0;
c.gridy = 1;
c.anchor = GridBagConstraints.NORTHWEST;
section.setConstraints(type,c);
frame.getContentPane ().add(type);

c.weightx = 10;
c.weighty = 15;
c.gridx = 5;
c.gridy = 1;
c.anchor = GridBagConstraints.NORTHWEST;
section.setConstraints(chButton,c);
frame.getContentPane ().add(chButton);


c.weightx = 1;
c.weighty = 1;
c.gridx = 8;
c.gridy = 0;
c.anchor = GridBagConstraints.NORTHEAST;
section.setConstraints(utextscroll,c);
frame.getContentPane ().add(utextscroll);

c.weightx = 0;
c.weighty = 15;
c.gridx = 6;
c.gridy = 1;
c.anchor = GridBagConstraints.NORTH;
section.setConstraints(pmButton,c);
frame.getContentPane ().add(pmButton);

c.weightx = 0;
c.weighty = 15;
c.gridx = 7;
c.gridy = 1;
c.anchor = GridBagConstraints.NORTH;
section.setConstraints(trButton,c);
frame.getContentPane ().add(trButton);

c.weightx = 15;
c.weighty = 15;
c.gridx = 8;
c.gridy = 1;
c.anchor = GridBagConstraints.NORTHEAST;
section.setConstraints(batButton,c);
frame.getContentPane ().add(batButton);

My pmButton and trButton over lap each other. If I put pmButton at NORTHWEST, it completely disappears. I'm not sure what I'm doing wrong.

Add on:
Okay I've done a couple of applets with GridBagLayout and when I put a component in a grid, it doesn't always stay in that grid. Like if I move the component WEST it goes into the grid next to it or the grid next to that. I thought it was suppose to be like html where a component stays in its grid no matter where you move it, but that doesn't seem to be the case. Am I missing something?

[edited by - DKN on June 1, 2004 3:03:22 AM]

Share this post


Link to post
Share on other sites
Have you checked out Sun''s tutorial on Layout Managers:

http://java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr/shortcourse.html



First make it work, then make it fast. --Brian Kernighan

The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)

Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
btw, you should read replies more carefully. Koroljov said GridLayout not GridBagLayout. It''s much easier to use.

Share this post


Link to post
Share on other sites
Thanks CaptainJester, that worked.

I wasn't following what Koroljov was saying...someone else suggested GridBagLayout before that. So I do read replies more carefully and now know what I'm doing with GridBagLayout, which works.

[edited by - DKN on June 1, 2004 4:33:44 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by DKN
Thanks CaptainJester, that worked.

I wasn''t following what Koroljov was saying...someone else suggested GridBagLayout before that. So I do read replies more carefully and now know what I''m doing with GridBagLayout, which works.

[edited by - DKN on June 1, 2004 4:33:44 PM]


I personally try to stay away from the GridBagLayout and instead just use a bunch of BorderLayouts and other non-gb layouts... unless there is a direct need for it which is very rarely as you can build almost anything with just BorderLayouts...

Share this post


Link to post
Share on other sites