Results 1 to 7 of 7
Thread: Layout Problem
- 01-09-2012, 03:43 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 17
- Rep Power
- 0
Layout Problem
Hello,
I want to make it so there are buttons in the left side with a BoxLayout and a textarea that covers the right side. This is my progress so far and I don't understand why it doesn't work.
Panel2 or the textarea doesn't seem to be showing, why is that?Java Code:public void sets() { JFrame frame = new JFrame(title); frame.setVisible(true); frame.setSize(400, 400); frame.setMinimumSize(new Dimension(400, 400)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(true); frame.setLayout(new BorderLayout()); JButton button1 = new JButton("Essay"); JButton button2 = new JButton("Novelle"); JButton button3 = new JButton("Artikel"); JTextArea textarea = new JTextArea(); JPanel panel2 = new JPanel(); panel2.setLayout(new BoxLayout(panel2, BoxLayout.PAGE_AXIS)); panel2.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); panel2.add(textarea); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); panel.add(button1); panel.add(Box.createRigidArea(new Dimension(0,10))); panel.add(button2); panel.add(Box.createRigidArea(new Dimension(0,10))); panel.add(button3); frame.add(panel, BorderLayout.WEST); frame.add(panel2, BorderLayout.EAST); frame.pack(); }
- 01-09-2012, 04:15 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
Re: Layout Problem
You are adding components after the parent container (JFrame) has been realized (set to visible). a) Call validate/revalidate followed by repaint when changing the components in this manner or b) (and better practice) add them prior to calling setVisible and pack
- 01-09-2012, 04:55 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 17
- Rep Power
- 0
Re: Layout Problem
Putting
at the end after frame.pack(); doesn't seem to fix the problem either. The Buttons are showing up but the textarea aren't.Java Code:frame.setVisible(true);
- 01-09-2012, 06:33 PM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
Re: Layout Problem
How do you know its 'not showing up'? Debug by adding some text to the text area, or set a color border around it to be sure it is 'showing up'.
- 01-09-2012, 07:07 PM #5
Member
- Join Date
- Nov 2011
- Posts
- 17
- Rep Power
- 0
Re: Layout Problem
Sorry, you're correct, it is working now thanks. Though you got me interested when you said a color border. What is the code for that?
- 01-09-2012, 08:19 PM #6
Re: Layout Problem
Moved from 'New to Java'
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 01-09-2012, 09:38 PM #7
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
Re: Layout Problem
Did you try google? First hit for me
How to Use Borders (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
Similar Threads
-
Problem with layout manager
By mDennis10 in forum New To JavaReplies: 8Last Post: 09-05-2011, 03:02 AM -
Layout problem
By miller.bartek in forum AWT / SwingReplies: 3Last Post: 01-11-2011, 07:50 PM -
problem in managing layout
By namreen in forum NetBeansReplies: 10Last Post: 09-04-2010, 09:41 AM -
java on mac - gui layout problem
By dalo in forum AWT / SwingReplies: 0Last Post: 06-19-2010, 10:15 AM -
[SOLVED] Layout Problem
By casid in forum New To JavaReplies: 4Last Post: 06-02-2009, 11:17 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks