Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-26-2010, 04:09 AM
Member
 
Join Date: Jan 2010
Posts: 5
Rep Power: 0
xhoneyskye is on a distinguished road
Default 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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-26-2010, 04:13 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,431
Rep Power: 8
Fubarable is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-26-2010, 04:16 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,431
Rep Power: 8
Fubarable is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-26-2010, 04:45 AM
Member
 
Join Date: Jan 2010
Posts: 5
Rep Power: 0
xhoneyskye is on a distinguished road
Default
yessssssssssssssssssss that was exactly what I was looking for. Thank you so much
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-26-2010, 04:46 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,431
Rep Power: 8
Fubarable is on a distinguished road
Default
Originally Posted by xhoneyskye View Post
yessssssssssssssssssss that was exactly what I was looking for. Thank you so much
Quite welcome!
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tab key in JTextArea KristoZ New To Java 1 09-25-2009 08:27 PM
About JTEXTAREA makpandian AWT / Swing 4 03-19-2009 07:53 AM
JTextArea setting newtojava7 New To Java 1 01-29-2008 03:57 AM
How to add a shortcut key from JTextArea sukatoa Advanced Java 2 01-28-2008 09:39 AM
JTextArea saytri New To Java 0 01-13-2008 02:07 AM


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