Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing Split pane view layout

Hello im implementing my firs split pane view and it doesn't seem to be working for me and i get the following output...

enter image description here

Here is the code.

//Create Album Panel
    albumPanel.setLayout(new FlowLayout());

    //Add List view
    albumList.setMinimumSize (new Dimension(150,150));
    albumPanel.add(new JScrollPane(albumList));


    //Add Text Area
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setEditable(false);
    textArea.setMinimumSize (new Dimension(150,150));
    albumPanel.add(textArea);

    //Split Pane
    JSplitPane splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, albumList, textArea);

    albumPanel.add(splitpane, BorderLayout.CENTER);
like image 976
Daniel Del Core Avatar asked Dec 31 '25 09:12

Daniel Del Core


1 Answers

You have set your albumPanel layout to FlowLayout but you try and use a BorderLayout constants when adding to the JSplitPane:

albumPanel.add(splitpane, BorderLayout.CENTER);

you should rather set the albumPanel layout to BorderLayout via new BorderLayout()

Also it is not a good idea for you to set the size of your components let the LayoutManager's do it for you.

like image 198
David Kroukamp Avatar answered Jan 01 '26 22:01

David Kroukamp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!