Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSplitPane (expandable closed)

 
Steve Ray
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I create a JSplitPane with oneTouchExpandable(true) but I want the panel to be collapsed when first displayed. I want to create a panel with collapsed panels on all 4 sides. Imagine a border layout with a panel in the middle and different panels on all four sides but collapsed. I have tried the following but doesn't work completly:

import java.awt.Dimension;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;

public class SplitpaneTest {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(new Dimension(600,600));
JPanel main = new JPanel();
main.setSize(new Dimension(500,500));
main.setMinimumSize(main.getPreferredSize());
JSplitPane spane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
new JTextArea("Top pane"),
main);
spane.setOneTouchExpandable(true);
spane.setResizeWeight(0.);
spane.setDividerLocation(0.0);

JSplitPane spane2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
new JTextArea("Left pane"),spane);
spane2.setOneTouchExpandable(true);
spane2.setResizeWeight(.0);
spane2.setDividerLocation(.0);

JSplitPane spane3 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,spane2,
new JTextArea("Right pane"));
spane3.setOneTouchExpandable(true);
spane3.setResizeWeight(1.0);
spane3.setDividerLocation(0);


JSplitPane spane4 = new JSplitPane(JSplitPane.VERTICAL_SPLIT,spane3,
new JTextArea("Bottom pane"));
spane4.setOneTouchExpandable(true);
spane4.setResizeWeight(1.0);
spane4.setDividerLocation(0);

}
}

Any ideas?
 
Swati Udas
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as i understand the requirement is -->

A splitpane with 4 panes.. one at each corner of a frame..all four shud look collapsed at the begining and should occupy 4 sections of the splitpane when expanded.!

I think u can add a Panel to each section of the splitpane and leave it collapsed.
Even if u have setdividerlocation=0.. one pane will be collapsed but the other side will show max size..so let the splitpanes be intermediate sizes and add JPanels in collapsed state at the corners.

Hope this helps !
 
Steve Ray
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand your suggestion, can you give me a little more detail?

As you can see in my example, there are 5 panels, the center one should be open and the panels on the four sides should be colapsed. I thought that I could do that by setting the dividerposition and setting the weights of either panel.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic