Results 1 to 4 of 4
  1. #1
    Ulrich is offline Member
    Join Date
    Apr 2012
    Rep Power

    Question JScrollPane is not aware of panelsize of the including JSplitPane-wing

    I want to show two JTables at either side of a JSplitPane. At top of either JTable there shall be some associated JButtons. To allow for scrolling, I will put the JTables to JScrollPanes. To arrange the JButtons and the JTables the way I described before I will put the JButtons NORTH and the JScrollPanes to the CENTER of JPanels. But when doing so, the JScrollPane is no longer scrolling. It is not aware of shrinking the JSplitPane. To show the effect I've build an example, where the left side of a JSplitPane is as described and the right wing contains just the JScrollPane. In the example the right side recognizes the size is scrollable.
    I wanted to add a PropertyChangeListener to the JSplitPane and to adjust the JPanel and the JScrollPane but neither of the components reacts to the setSize()-methods.
    I'm looking for an explanation and more than this to a solution for my problem.

    Java Code:
    package de.gombers.zos.smf.ui;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import java.util.*; 
    import javax.swing.*;
    import javax.swing.border.Border;
    public class MusterSplitPane extends JSplitPane implements PropertyChangeListener {
    	String[] fields;
    	String[] titles;
    	JButton select = new JButton("Select"); 
    	Vector<String[]> sfields = new Vector<String[]>(20, 10);
    	Border redline, greenline;
    	static Dimension dimension=new Dimension(600, 400);
    	public MusterSplitPane(String[] fields, String[] titles) {
    		redline = BorderFactory.createLineBorder(;
    		greenline = BorderFactory.createLineBorder(;
    		// left Pane
    		String[][] fieldtab = new String[fields.length][2];
    		String[] colNames = {"Fields", "Titles"};
    		for (int i=0; i<fields.length; i++) {
    		JTable lTab = new JTable(fieldtab, colNames );
    		JScrollPane lPane=new JScrollPane();
    		lPane.setSize(150, 150);
    		lTab.setSize(150, 150);
    		JPanel leftPane = new JPanel();
    		leftPane.add(new JButton("myButton"), BorderLayout.NORTH);
    		leftPane.add(lPane, BorderLayout.CENTER);
    		leftPane.setSize(150, 150);
    		// right Pane
    		JTable rTab = new JTable(fieldtab, colNames );
    		JScrollPane rPane=new JScrollPane();
    	public void propertyChange(PropertyChangeEvent pce) {
    		System.out.println(pce.getPropertyName() + "  " + this.getDividerLocation() + " PanelHeigth=" + this.getHeight());
    	public static void main(String[] args) {
    		JFrame jf = new JFrame("Test JSplitPane");
    		String[] fields={"one", "two", "three", "four"};
    		String[] titles={"isOne", "isTwo", "isThree", "isFour"};
    		MusterSplitPane msp = new MusterSplitPane(fields, titles);

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: JScrollPane is not aware of panelsize of the including JSplitPane-wing

    Your leftPane JPanel will use its default FlowLayout, not BorderLayout since you never specifically give it a layout manager. Also, you should never set sizes of things and only occasionally set preferred sizes.

  3. #3
    Ulrich is offline Member
    Join Date
    Apr 2012
    Rep Power

    Default Re: JScrollPane is not aware of panelsize of the including JSplitPane-wing

    Thank you, that fixed it. Though I've have no clue why scrolling did not work for FlowLayout. Can you tell - I feel uncomfortable not understanding this.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: JScrollPane is not aware of panelsize of the including JSplitPane-wing

    FlowLayout associates a preferredSize that lays out all the components, at their preferredSizes, in a single row.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. JSplitPane separator customization
    By azzardo in forum AWT / Swing
    Replies: 1
    Last Post: 11-16-2010, 02:31 PM
  2. displaying JSplitPane in JPanel
    By sandysm in forum AWT / Swing
    Replies: 4
    Last Post: 07-26-2010, 10:13 AM
  3. Managing jPanels in jSplitPane
    By calexander in forum Advanced Java
    Replies: 6
    Last Post: 11-13-2008, 08:06 PM
  4. JSplitPane nightmare
    By SwinGirl in forum SWT / JFace
    Replies: 1
    Last Post: 05-01-2008, 09:24 PM
  5. I need create a JSplitPane
    By Daniel in forum AWT / Swing
    Replies: 1
    Last Post: 07-05-2007, 07:12 AM

Posting Permissions

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