List of usage examples for javax.swing JSplitPane resetToPreferredSizes
public void resetToPreferredSizes()
JSplitPane
layout based on the preferred size of the children components. From source file:VerticalSplit.java
public static void main(String args[]) { JFrame vFrame = new JFrame("Vertical Split"); vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComponent leftButton = new JButton("Left"); JComponent rightButton = new JButton("Right"); final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setOneTouchExpandable(true); splitPane.setLeftComponent(leftButton); splitPane.setRightComponent(rightButton); ActionListener oneActionListener = new ActionListener() { public void actionPerformed(ActionEvent event) { splitPane.resetToPreferredSizes(); }/*w w w .jav a 2 s . c o m*/ }; ((JButton) rightButton).addActionListener(oneActionListener); ActionListener anotherActionListener = new ActionListener() { public void actionPerformed(ActionEvent event) { splitPane.setDividerLocation(10); splitPane.setContinuousLayout(true); } }; ((JButton) leftButton).addActionListener(anotherActionListener); vFrame.getContentPane().add(splitPane, BorderLayout.CENTER); vFrame.setSize(300, 150); vFrame.setVisible(true); }
From source file:ExpandableSplit.java
public static void main(String args[]) { String title = (args.length == 0 ? "Expandable Split" : args[0]); JFrame vFrame = new JFrame(title); vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComponent leftButton = new JButton("Top"); JComponent rightButton = new JButton("Bottom"); final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setOneTouchExpandable(true); splitPane.setLeftComponent(leftButton); splitPane.setRightComponent(rightButton); ActionListener oneActionListener = new ActionListener() { public void actionPerformed(ActionEvent event) { splitPane.resetToPreferredSizes(); }/*from w w w . j a v a2s . c o m*/ }; ((JButton) rightButton).addActionListener(oneActionListener); ActionListener anotherActionListener = new ActionListener() { public void actionPerformed(ActionEvent event) { splitPane.setDividerLocation(10); splitPane.setContinuousLayout(true); } }; ((JButton) leftButton).addActionListener(anotherActionListener); vFrame.getContentPane().add(splitPane, BorderLayout.CENTER); vFrame.setSize(300, 150); vFrame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame vFrame = new JFrame("Vertical Split"); vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComponent leftButton = new JButton("Left"); JComponent rightButton = new JButton("Right"); final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setOneTouchExpandable(true); splitPane.setLeftComponent(leftButton); splitPane.setRightComponent(rightButton); ActionListener oneActionListener = new ActionListener() { public void actionPerformed(ActionEvent event) { splitPane.resetToPreferredSizes(); }/*from ww w . j a va 2 s . c o m*/ }; ((JButton) rightButton).addActionListener(oneActionListener); ActionListener anotherActionListener = new ActionListener() { public void actionPerformed(ActionEvent event) { splitPane.setDividerLocation(10); splitPane.setContinuousLayout(true); } }; ((JButton) leftButton).addActionListener(anotherActionListener); HierarchyListener hierarchyListener = new HierarchyListener() { public void hierarchyChanged(HierarchyEvent e) { long flags = e.getChangeFlags(); if ((flags & HierarchyEvent.SHOWING_CHANGED) == HierarchyEvent.SHOWING_CHANGED) { splitPane.setDividerLocation(.75); } } }; splitPane.addHierarchyListener(hierarchyListener); vFrame.add(splitPane, BorderLayout.CENTER); vFrame.setSize(300, 150); vFrame.setVisible(true); }