Skip to main content
gamedev.net
🔒 Locked

[java] Locations

Started by DKN May 30, 2004 at 4:55 PM 6 replies 550+ views
Original Post
DKN
DKN
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]
DKN
DKN
nvm I figured out that FlowLayout can put things in columns.
Koroljov
Koroljov
Maybe you should consider a GridLayout?
Why do my programs never work on other computers?
DKN
DKN
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]
CaptainJester
CaptainJester
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
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
DKN
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]
garazdawi
garazdawi
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...
garazdawi - 'I put the laughter back in slaughter'

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.