JSplitPane: can I programatically do what the oneTouchExpandable does?

Hi All,

I'm looking for a method call I can use to do the same thing as the oneTouchExpandable buttons do on the JSplitPane divider. I basically want to call a method to collapse the left hand side and then same/simlar call to restore it. Is such a method available? I know I can do setDividerLocation(0), but I'm looking for something less manual. Thanks in advance.

[382 byte] By [vintia] at [2007-11-26 23:54:48]
# 1
look at the source code to see what oneTouchExpandable does
Michael_Dunna at 2007-7-11 15:37:44 > top of Java-index,Desktop,Core GUI APIs...
# 2

hi,

just check this program, just click on the button then you can came to know what is happing

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.BorderFactory;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.JTextField;

public class SplitPaneDemo extends JFrame

{

JTextField jtf = new JTextField(15);

String cols[] = {"asdfasdfasdf","asdfasdfsadf","asdfasdf","aaaaaaaaaaaa","aaaaaaaaaaaaaaaaa"};

JPanel jp = new JPanel();

JPanel jp1 = new JPanel();

JPanel jp2 = new JPanel(new BorderLayout());

JTable tbl = new JTable(10,10);

JScrollPane jsp = new JScrollPane(tbl);

public SplitPaneDemo() {

JButton jb = new JButton("sdf");

tbl.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

jsp.setAutoscrolls(true);

jb.addActionListener( new ActionListener(){

public void actionPerformed(ActionEvent e){

if(jp1.isVisible())

jp1.setVisible(false);

else

jp1.setVisible(true);

}

});

jp.setEnabled(true);

jp.add(jsp, "Center");

jp.setBorder(BorderFactory.createBevelBorder(1));

jp1.add(new JLabel("asdfeeeeeeeeeeeeeeeeee"));

jp2.add(jsp, "Center");

jp2.add(jp1, "West");

getContentPane().add(new JPanel().add(jb),"West");

getContentPane().add(jp2, "Center");

pack();

setDefaultCloseOperation(EXIT_ON_CLOSE);

setVisible(true);

}

public static void main(String[] args)

{

new SplitPaneDemo();

}

}

hopes it helps

daya

dayanandabva at 2007-7-11 15:37:44 > top of Java-index,Desktop,Core GUI APIs...
# 3
Hey these are great suggestions. Thanks for the help!
vintia at 2007-7-11 15:37:44 > top of Java-index,Desktop,Core GUI APIs...