
01-26-2010, 04:09 AM
|
|
Member
|
|
Join Date: Jan 2010
Posts: 5
Rep Power: 0
|
|
adding jtextarea
So... well I'm new to Java, this is the current code I have. I want to add a textarea at the east of everthing. Could someone help me with this or at least give me an idea on how? Please and thanks.
|
Code:
|
package javaapplication1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame implements ActionListener
{
Container thing = new Container();
JTextField textfield1= new JTextField("jtextfield");
JTextField textfield2= new JTextField("jtextfield");
JTextArea textarea = new JTextArea("textarea");
JButton button = new JButton("push");
public Main ()
{
this.setSize(200, 200);
thing.setLayout(new GridLayout(2,1));
thing.add(textfield1);
thing.add(textfield2);
thing.add(button);
button.addActionListener(this);
this.setLayout(new BorderLayout());
this.add(textfield1, BorderLayout.NORTH);
this.add(textfield2, BorderLayout.CENTER);
this.add(button, BorderLayout.SOUTH);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
Main m = new Main();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(button))
{
System.out.println("pushed!");
}
}
} |
Last edited by Fubarable; 01-26-2010 at 04:10 AM.
Reason: code tags added
|
|

01-26-2010, 04:13 AM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,431
Rep Power: 8
|
|
|
Hello, and welcome to the forum. I hope you don't mind that I changed your color tags into code tags since they make your code much easier to read.
My obvious first question is have you tried to add your textfield to the JFrame (this), well actually it's contentPane, BorderLayout.EAST?
__________________
When posting code, please use code tags so that your code is readable. To do this, place the tag [code] before your block of code and [/code] after your block of code.
How to use Code Tags
|
|

01-26-2010, 04:16 AM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,431
Rep Power: 8
|
|
Ah, I see what you're trying to do. To solve this you need to nest some of your components in another JPanel and add that to the BorderLayout.CENTER position of the JFrame, then add the textarea BorderLayout.EAST. e.g.,
|
Code:
|
this.setLayout(new BorderLayout());
JPanel centerPanel = new JPanel(new BorderLayout());
centerPanel.add(textfield1, BorderLayout.NORTH);
centerPanel.add(textfield2, BorderLayout.CENTER);
centerPanel.add(button, BorderLayout.SOUTH);
add(centerPanel, BorderLayout.CENTER);
add(textarea, BorderLayout.EAST); |
__________________
When posting code, please use code tags so that your code is readable. To do this, place the tag [code] before your block of code and [/code] after your block of code.
How to use Code Tags
|
|

01-26-2010, 04:45 AM
|
|
Member
|
|
Join Date: Jan 2010
Posts: 5
Rep Power: 0
|
|
yessssssssssssssssssss that was exactly what I was looking for. Thank you so much
|
|

01-26-2010, 04:46 AM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,431
Rep Power: 8
|
|
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +2. The time now is 11:00 AM.
|
|
VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org