Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: JTextArea Problem

  1. #1
    Junior Member grimx's Avatar
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default JTextArea Problem

    I have a JFrame with a JBoxLayout set Y_AXIS and inside the JFrame i have two JPanels
    each with some componets inside them and have put both JPanels inside the JFrame,
    but for some reason the JPanel with the JTextArea does not show up.

    Here is my source code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
     
    public class FileTest extends JFrame implements ActionListener {
    	private BoxLayout vbox;
    	private JPanel panel;
    	private JPanel topPanel;
    	private JTextArea txtBox;
    	private JButton openBtn;
    	private JButton closeBtn;
     
    	public FileTest() {
    		super("FileTest");
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    		vbox = new BoxLayout(this, BoxLayout.Y_AXIS);
     
    		txtBox = new JTextArea("Hello World", 10, 80);
     
    		topPanel = new JPanel();
    		topPanel.add(txtBox);
    		add(topPanel);
     
    		openBtn = new JButton("Open");
    		closeBtn = new JButton("Close");
     
    		panel = new JPanel();
    		panel.add(openBtn);
    		panel.add(closeBtn);
    		add(panel);
     
    		pack();
    		setVisible(true);
    	}
     
    	@Override
    	public void actionPerformed(ActionEvent arg0) {
    		// TODO Auto-generated method stub
     
    	}
     
     
    	public static void main(String[] args) {
    		FileTest test = new FileTest();
    	}
     
    }
    Ubuntu 9.10 2.6.31-14-generic
    AMD Sempron(tm) Processor LE-1300
    2 GIGS RAM, 320 GIG Hard Drive
    NVIDIA GeForce 6160 SE integrated graphics


  2. #2
    Member
    Join Date
    Feb 2011
    Posts
    55
    My Mood
    Tolerant
    Thanks
    1
    Thanked 16 Times in 15 Posts

    Default Re: JTextArea Problem

    Something doesn't seem right about the layout. do a System.out.println(this.getLayout()) to see what I mean.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JTextArea Problem

    I presume you want to use that BoxLayout for the JFrame layout? Try setting the layout of the content pane instead of the JFrame.
    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

  4. #4
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: JTextArea Problem

    --NeverMind, copeg got it :<--
    Last edited by newbie; March 10th, 2011 at 07:15 PM.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

Similar Threads

  1. How To: Add line numbers to your JTextArea
    By Freaky Chris in forum Java Swing Tutorials
    Replies: 11
    Last Post: October 15th, 2013, 10:22 PM
  2. How would you get a JTextArea to know how many lines it had?
    By javapenguin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 20th, 2011, 07:58 PM
  3. Expanding JTextArea
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 10
    Last Post: November 27th, 2010, 10:15 PM
  4. JTextArea output problem
    By grimx in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 8th, 2010, 07:54 PM
  5. Convert contents of JTextArea / JEditorPane to PDF
    By rangarajank in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: September 30th, 2009, 02:38 PM