Results 1 to 7 of 7
Thread: JTextArea not visable!
- 02-18-2013, 03:59 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 4
- Rep Power
- 0
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.
- 02-18-2013, 04:16 PM #2
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!
- 02-18-2013, 04:36 PM #3
Member
- Join Date
- Jul 2012
- Posts
- 4
- Rep Power
- 0
Re: JTextArea not visable!
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);
}
}
- 02-18-2013, 04:42 PM #4
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!
- 02-18-2013, 04:53 PM #5
Senior Member
- Join Date
- Oct 2010
- Posts
- 316
- Rep Power
- 3
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.
- 02-18-2013, 04:57 PM #6
Re: JTextArea not visable!
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-18-2013, 05:10 PM #7
Senior Member
- Join Date
- Oct 2010
- Posts
- 316
- Rep Power
- 3
Similar Threads
-
JTextArea Help
By gavin.87 in forum Java GamingReplies: 1Last Post: 04-11-2012, 05:28 PM -
ERRORS: set visable
By Johanis in forum New To JavaReplies: 1Last Post: 11-07-2010, 12:03 PM -
JTextArea on PopUp -JTextArea isn't editable
By Richy76 in forum AWT / SwingReplies: 3Last Post: 02-01-2010, 07:51 PM -
Tab key in JTextArea
By KristoZ in forum New To JavaReplies: 1Last Post: 09-25-2009, 07:27 PM -
JTextArea
By saytri in forum New To JavaReplies: 0Last Post: 01-13-2008, 01:07 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks