JSpltpane resizing

hi all,

i have separated two panels using JSplitpane(VERTICAL_SPLIT)..

when i resize the splitpane the bottom panel is getting smaller.. but i want the bottom panel to be in same size and top panel size to be varied..

i tried by adding JSplitPane to the JScrollPane but scrollpane is not scrolling.

is there any solution for this ?

Any help will really be appreciated.

regards

suresh

[432 byte] By [Suresh22a] at [2007-11-26 17:46:25]
# 1
Read the tutorial: http://java.sun.com/docs/books/tutorial/uiswing/components/splitpane.html#dividerHint: setResizeWeight
Rodney_McKaya at 2007-7-9 5:18:00 > top of Java-index,Desktop,Core GUI APIs...
# 2

Your question doesn't make any sense.

The point of using a split pane is that as you move the divider one area gets bigger and the other area gets smaller.

If you want the panel to remain the same size but to have scrollbars appear as the divider is moved, then you add your panel to a scrollPane and then add the scrollPane to the splitPane.

Here is an example of this:

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=603930

camickra at 2007-7-9 5:18:00 > top of Java-index,Desktop,Core GUI APIs...
# 3

sorry i confused u all..

actually my problem is, when i resize the splitpane its getting resize up to the bottom of the frame and not beyond that.. but what i need is, the splitpane should keep on growing and i should view it in scrollpane..

i tried by doing this...but its not working..

JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, bottomPanel);

JScrollPane scroll = new JScrollPane(split);

getContentPane().add(scroll);

is there anyother way of doing this ?

regards

suresh

Suresh22a at 2007-7-9 5:18:00 > top of Java-index,Desktop,Core GUI APIs...
# 4

Well, my example shows you how to listen for changes in the split pane location. So I guess every time you change the location of the divide you need to change the preferred size of the component that can grow or shrink. This should cause the preferred size of the split pane to change. And the scrollbars should appear when the preferred size of the split pane is greater than the size of the scroll pane.

camickra at 2007-7-9 5:18:00 > top of Java-index,Desktop,Core GUI APIs...
# 5

i tried your example by changing thecomponent size, but the componet isn't growing..

import java.awt.*;

import java.beans.*;

import java.awt.event.*;

import javax.swing.*;

public class SplitPaneResizing_1 extends JFrame implements PropertyChangeListener

{

JSplitPane top;

JSplitPane down;

private javax.swing.JPanel detailPnl;

private javax.swing.JScrollPane detailScrlPane;

JPanel pnlTop;

public SplitPaneResizing_1()

{

JSplitPane main = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

getContentPane().add( main );

pnlTop = new JPanel();

JPanel pnlDown = new JPanel();

JScrollPane pane = new JScrollPane(pnlTop,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

main.setTopComponent( pane );

main.setBottomComponent( pnlDown );

top = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);

top.setContinuousLayout(true);

pnlTop.add(top);

down = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);

pnlDown.add(down);

top.setLeftComponent( createPanel(Color.RED) );

top.setRightComponent( createPanel(Color.GREEN) );

down.setLeftComponent( createPanel(Color.BLUE) );

down.setRightComponent( createPanel(Color.WHITE) );

// This code will keep the top/down scroll panes in sync

//

top.addPropertyChangeListener( this );

down.addPropertyChangeListener( this );

}

private JComponent createPanel(Color background)

{

JPanel panel = new JPanel();

panel.setPreferredSize( new Dimension(200, 100) );

panel.setBackground( background );

panel.add( new JLabel( background.toString() ) );

return new JScrollPane(panel);

}

public void propertyChange(PropertyChangeEvent e)

{

if ("dividerLocation".equals(e.getPropertyName()))

{

Object source = e.getSource();

JSplitPane target = (source.equals(top)) ? down : top;

int location = ((Integer)e.getNewValue()).intValue();

System.out.println(location);

if(location>=385)

{

pnlTop.setPreferredSize(new Dimension(pnlTop.getWidth()+30,pnlTop.getHeight()));

}

if (location != target.getDividerLocation())

target.setDividerLocation( location );

}

}

public static void main(String[] args)

{

SplitPaneResizing_1 frame = new SplitPaneResizing_1();

frame.setDefaultCloseOperation( EXIT_ON_CLOSE );

frame.setSize(500, 300);

frame.setLocationRelativeTo( null );

frame.setVisible(true);

}

}

Suresh22a at 2007-7-9 5:18:00 > top of Java-index,Desktop,Core GUI APIs...
# 6
now its working...thanks for all the help camickr..regardssuresh
Suresh22a at 2007-7-9 5:18:00 > top of Java-index,Desktop,Core GUI APIs...