PDA

View Full Version : Java layout problem



FirePenguins
November 11th, 2007, 09:51 PM
Hi, this is my first post here. Been lurking around for awhile though ;) making use of all the great posts, tutorials, guides, etc... Anyways I've got a problem with my layout for a java applet and maybe some one can help. Thanks!!

So basically what I want is for there to be a JTextField (chatInput) at the bottom of the screen, with a JTextArea (displayArea) just above that, and then a JPanel (gamePanel) at the top or middle of the screen. I can't seem to get it to work right though :( right now the applet fails to init because of the layout and when i change it the layout isn't right. If I cut gamePanel altogether it loads fine, but I kinda need gamePanel :p

Any help is appreciated thanks!!


chatInput = new JTextField( 50 );
chatInput.addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent event )
{
sendMessage( event.getActionCommand() );
chatInput.setText( "" );
}
}
);

chatPanel = new JPanel();
chatPanel.setLayout( new BorderLayout() );

displayArea = new JTextArea( 4, 50 );
displayArea.setEditable( false );

chatPanel.add( new JScrollPane( displayArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ), BorderLayout.NORTH );
chatPanel.add( chatInput, BorderLayout.SOUTH );

gamePanel = new JPanel();
gamePanel.setLayout( new GridLayout( 12, 12, 0, 0 ) );

bigPanel = new JPanel();
bigPanel.setLayout( new BorderLayout() );
bigPanel.add( gamePanel, BorderLayout.NORTH );
bigPanel.add( chatPanel, BorderLayout.SOUTH );

add( bigPanel, BorderLayout.CENTER );

Yeldarb
November 11th, 2007, 11:30 PM
You should definitely try using a program to help you do your GUI stuff so you don't have to do it by hand. Try Jigloo for Eclipse, it's pretty nice.

FirePenguins
November 12th, 2007, 08:47 AM
Yeah I probably should do that. I like to try and do things just with my code cause I figure that way I actually understand what is going on better, but I'll look into eclipse and jigloo.

Yeldarb
November 12th, 2007, 03:21 PM
Yeah I probably should do that. I like to try and do things just with my code cause I figure that way I actually understand what is going on better, but I'll look into eclipse and jigloo.
Yeah, the nice thing about Jigloo is it will generate the code and if you want to go in manually and fine-tune or add to things by hand it will leave your code untouched (so you can still use the IDE to make other changes, etc).