Search code examples
javaswingjscrollpanejtextareaborder-layout

JTextArea on left of JPanel


I have a main gui class and a gui log class. The gui log class extends JPanel and simply adds a JTextField which will be used to print logging statements. I add the JTextfield(Which is in a scroll pane) to the panel with

add(scrollPane, BorderLayout.WEST);

this class is then added to my main gui class which extends JFrame and uses a BorderLayout. The panel is first added to a JSplitPane (using Vertical split) and then the SplitPane is added using

getContentPane().add(splitPane);

My problem is that I want the JTextfield within the log panel to be at the very left of the screen, however no matter what BorderLayout setting I use(CENTER, EAST, SOUTH...) it always remains in the center.

Anyone know how I can solve this?

Also do you know how I can get the JTExt area to resize as I resize the split pane?

Thanks

Images: enter image description here

The left is what I'm getting, the right is what I want.


Solution

  • The JPanel on the bottom, the one that holds the JTextArea is likely using JPanel's default FlowLayout, a layout that will try to center components added. For your gui to work, this JPanel must use a BorderLayout via setLayout(new BorderLayout(...)) (the ... is either blank if you accept the defaults, or has two int constants for horizontal and vertical gaps for the layout).