Results 1 to 7 of 7
  1. #1
    rosishere is offline Member
    Join Date
    Jul 2012
    Posts
    4
    Rep Power
    0

    Angry JTextArea not visable!

    So, i am new to java, and i just figured out how to position JPanles.

    I tought that making a text editing program would be a good start.
    But my problem is that wen i position my JPanel holding my JTextArea it just disapears.
    i use a JButton called Test to check where the edge of my JPanels are and it worked fine for all the things i have done so far, but this time it just disapeared.
    Here is a link to a picture: https://dl.dropbox.com/u/90315377/Pr...roblems/JP.png

    i show 2 JFrames, 1 with the test button and 1 with the textarea (that disapears).

    to make things clear, incase people don't understand my bad english :
    the TextArea is not there and i have no clue why its not there so can anyone please point me at what i have done wrong.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default Re: JTextArea not visable!

    The best way to get help is to provide an SSCCE that demonstrates exactly what's going on. I am behind a firewall that blocks dropbox, so runnable code is the best way to demonstrate the problem and get help.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    rosishere is offline Member
    Join Date
    Jul 2012
    Posts
    4
    Rep Power
    0

    Default Re: JTextArea not visable!

    Quote Originally Posted by rosishere View Post
    So, i am new to java, and i just figured out how to position JPanles.

    I tought that making a text editing program would be a good start.
    But my problem is that wen i position my JPanel holding my JTextArea it just disapears.
    i use a JButton called Test to check where the edge of my JPanels are and it worked fine for all the things i have done so far, but this time it just disapeared.
    Here is a link to a picture: https://dl.dropbox.com/u/90315377/Pr...roblems/JP.png

    i show 2 JFrames, 1 with the test button and 1 with the textarea (that disapears).

    to make things clear, incase people don't understand my bad english :
    the TextArea is not there and i have no clue why its not there so can anyone please point me at what i have done wrong.
    Here is the code


    import javax.swing.*;


    public class Mainframe {

    public static void main (String []args){

    //creating JFrame
    JFrame frame = new JFrame("Test Gui v.2");

    //creating JPanels
    JPanel p1 = new JPanel();
    JPanel p2 = new JPanel();
    JPanel p3 = new JPanel();

    //creating JButtons for loading saving
    JButton b1 = new JButton("Save(b1)");
    JButton b2 = new JButton("Load(b2)");

    JButton Test = new JButton("Testing location!");

    //creating JTextArea
    JTextArea ta = new JTextArea();

    //adding settings to JFrame
    frame.setSize(500, 600);
    frame.setLayout(null);
    frame.setVisible(true);
    frame.setResizable(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    //positioning JPanels (p1 and p2) on JFrame (frame)
    p1.setBounds(-20, -5, 125, 32);
    p2.setBounds(60, -5, 125, 32);
    p3.setBounds(-160, 25, 495, 595);

    //adding JButtons (b1 and b2) to JPanels (p1 and p2)
    p1.add(b1);
    p2.add(b2);

    //adding ta to p3
    p3.add(ta);

    //adding JPannels (p1, p2 and p3) to JFrame (frame)
    frame.add(p1);
    frame.add(p2);
    frame.add(p3);
    }

    }

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default Re: JTextArea not visable!

    When posting code, please use the code tags to preserve formatting.

    You're going to want to use a layout manager. Setting the bounds on components is almost never a good idea, which is probably contributing to your problem here. Recommended reading: Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: JTextArea not visable!

    Hi rosishere,

    The JTextArea does not have a size by default, this can be corrected by calling the setPreferredSize() method of JTextArea.

    Edit: I would also like to second KevinWorkman suggestion on layout managers.

    Regards.
    Last edited by Ronin; 02-18-2013 at 04:57 PM.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default Re: JTextArea not visable!

    Quote Originally Posted by Ronin View Post
    Hi rosishere,

    The JTextArea does not have a size by default, this can be corrected by calling the setPreferredSize() method of JTextArea.

    Regards.
    Or better yet, using a layout manager.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: JTextArea not visable!

    Quote Originally Posted by KevinWorkman View Post
    Or better yet, using a layout manager.
    Definately the way to go. I assumed the OP had a reason for hardcoding the locations though it can cause a world of pain when resizing.

Similar Threads

  1. JTextArea Help
    By gavin.87 in forum Java Gaming
    Replies: 1
    Last Post: 04-11-2012, 05:28 PM
  2. ERRORS: set visable
    By Johanis in forum New To Java
    Replies: 1
    Last Post: 11-07-2010, 12:03 PM
  3. JTextArea on PopUp -JTextArea isn't editable
    By Richy76 in forum AWT / Swing
    Replies: 3
    Last Post: 02-01-2010, 07:51 PM
  4. Tab key in JTextArea
    By KristoZ in forum New To Java
    Replies: 1
    Last Post: 09-25-2009, 07:27 PM
  5. JTextArea
    By saytri in forum New To Java
    Replies: 0
    Last Post: 01-13-2008, 01:07 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •