Example usage for javax.swing JSplitPane setDividerLocation

List of usage examples for javax.swing JSplitPane setDividerLocation

Introduction

In this page you can find the example usage for javax.swing JSplitPane setDividerLocation.

Prototype

@BeanProperty(description = "The location of the divider.")
public void setDividerLocation(int location) 

Source Link

Document

Sets the location of the divider.

Usage

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   w  w w  .  j ava  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);
}

From source file:UseActions.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Use TextAction");
    Container contentPane = frame.getContentPane();
    Dimension empty = new Dimension(0, 0);

    final JTextArea leftArea = new JTextArea();
    JScrollPane leftScrollPane = new JScrollPane(leftArea);
    leftScrollPane.setPreferredSize(empty);

    final JTextArea rightArea = new JTextArea();
    JScrollPane rightScrollPane = new JScrollPane(rightArea);
    rightScrollPane.setPreferredSize(empty);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftScrollPane, rightScrollPane);

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);/*from   ww w  .j  a  v a2 s. com*/
    JMenu menu = new JMenu("Options");
    menuBar.add(menu);
    JMenuItem menuItem;

    Action readAction = leftArea.getActionMap().get(DefaultEditorKit.readOnlyAction);
    menuItem = menu.add(readAction);
    menuItem.setText("Make read-only");
    Action writeAction = leftArea.getActionMap().get(DefaultEditorKit.writableAction);
    menuItem = menu.add(writeAction);
    menuItem.setText("Make writable");

    menu.addSeparator();

    Action cutAction = leftArea.getActionMap().get(DefaultEditorKit.cutAction);
    menuItem = menu.add(cutAction);
    menuItem.setText("Cut");
    Action copyAction = leftArea.getActionMap().get(DefaultEditorKit.copyAction);
    menuItem = menu.add(copyAction);
    menuItem.setText("Copy");
    Action pasteAction = leftArea.getActionMap().get(DefaultEditorKit.pasteAction);
    menuItem = menu.add(pasteAction);
    menuItem.setText("Paste");

    contentPane.add(splitPane, BorderLayout.CENTER);
    frame.setSize(400, 250);
    frame.setVisible(true);
    splitPane.setDividerLocation(.5);
}

From source file:Main.java

public static JSplitPane setDividerLocation(final JSplitPane splitter, final double proportion) {
    if (splitter.isShowing()) {
        if (splitter.getWidth() > 0 && splitter.getHeight() > 0) {
            splitter.setDividerLocation(proportion);
        } else {//from  w  ww.  j av  a 2s. co m
            splitter.addComponentListener(new ComponentAdapter() {
                @Override
                public void componentResized(ComponentEvent ce) {
                    splitter.removeComponentListener(this);
                    setDividerLocation(splitter, proportion);
                }
            });
        }
    } else {
        splitter.addHierarchyListener(new HierarchyListener() {
            @Override
            public void hierarchyChanged(HierarchyEvent e) {
                if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 && splitter.isShowing()) {
                    splitter.removeHierarchyListener(this);
                    setDividerLocation(splitter, proportion);
                }
            }
        });
    }
    return splitter;
}

From source file:Main.java

/**
 * Force divider location for a JSplitPan with int position.
 *
 * @param splitter//from   w w  w.j av a 2  s.  co m
 * @param position
 * @return
 */
public static JSplitPane setDividerLocation(final JSplitPane splitter, final int position) {
    if (splitter.isShowing()) {
        if (splitter.getWidth() > 0 && splitter.getHeight() > 0) {
            splitter.setDividerLocation(position);
        } else {
            splitter.addComponentListener(new ComponentAdapter() {
                @Override
                public void componentResized(ComponentEvent ce) {
                    splitter.removeComponentListener(this);
                    setDividerLocation(splitter, position);
                }
            });
        }
    } else {
        splitter.addHierarchyListener(new HierarchyListener() {
            @Override
            public void hierarchyChanged(HierarchyEvent e) {
                if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 && splitter.isShowing()) {
                    splitter.removeHierarchyListener(this);
                    setDividerLocation(splitter, position);
                }
            }
        });
    }
    return splitter;
}

From source file:Main.java

/**
 * Force divider location for a JSplitPan in percent.
 *
 * @param splitter/*from  w  w w .  j a v a 2 s .  co m*/
 * @param proportion
 * @return
 */
public static JSplitPane setDividerLocation(final JSplitPane splitter, final double proportion) {
    if (splitter.isShowing()) {
        if (splitter.getWidth() > 0 && splitter.getHeight() > 0) {
            splitter.setDividerLocation(proportion);
        } else {
            splitter.addComponentListener(new ComponentAdapter() {
                @Override
                public void componentResized(ComponentEvent ce) {
                    splitter.removeComponentListener(this);
                    setDividerLocation(splitter, proportion);
                }
            });
        }
    } else {
        splitter.addHierarchyListener(new HierarchyListener() {
            @Override
            public void hierarchyChanged(HierarchyEvent e) {
                if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 && splitter.isShowing()) {
                    splitter.removeHierarchyListener(this);
                    setDividerLocation(splitter, proportion);
                }
            }
        });
    }
    return splitter;
}

From source file:Main.java

/**
 * Moves the supplied <code>JSplitPane</code> divider to the specified <code>proportion</code>.
 * Valid values for <code>proportion</code> range from <code>0.0F<code>
 * to <code>1.0F</code>.  For example, a <code>proportion</code> of <code>0.3F</code> will move the
 * divider to 30% of the "size" (<i>width</i> for horizontal split, <i>height</i> for vertical split) of the
 * split container that contains the specified <code>Dockable</code>.  If a <code>proportion</code> of less
 * than <code>0.0F</code> is supplied, the value </code>0.0F</code> is used.  If a <code>proportion</code>
 * greater than <code>1.0F</code> is supplied, the value </code>1.0F</code> is used.
 * <br/>/*from   w w  w .j a va2  s .c o m*/
 * This method should be effective regardless of whether the split layout in question has been fully realized
 * and is currently visible on the screen.  This should alleviate common problems associated with setting
 * percentages of unrealized <code>Component</code> dimensions, which are initially <code>0x0</code> before
 * the <code>Component</code> has been rendered to the screen.
 * <br/>
 * If the specified <code>JSplitPane</code> is <code>null</code>, then this method returns with no action
 * taken.
 *
 * @param split the <code>JSplitPane</code> whose divider location is to be set.
 * @param proportion a double-precision floating point value that specifies a percentage,
 * from zero (top/left) to 1.0 (bottom/right)
 * @see #getSplitPaneSize(JSplitPane)
 * @see JSplitPane#setDividerLocation(double)
 */
public static void setSplitDivider(final JSplitPane split, float proportion) {
    if (split == null)
        return;

    proportion = Math.max(0f, proportion);
    final float percent = Math.min(1f, proportion);
    int size = getSplitPaneSize(split);

    if (split.isVisible() && size > 0 && EventQueue.isDispatchThread()) {
        split.setDividerLocation(proportion);
        split.validate();
        return;
    }

    EventQueue.invokeLater(new Runnable() {
        public void run() {
            setSplitDivider(split, percent);
        }
    });
}

From source file:com.intuit.tank.tools.debugger.PanelBuilder.java

static Component createRightPanel(final AgentDebuggerFrame frame) {
    JPanel ret = new JPanel(new BorderLayout());
    ret.add(BorderLayout.NORTH, new InfoHeaderPanel(frame));
    JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true);
    pane.setTopComponent(new VariablesPanel(frame));
    pane.setBottomComponent(frame.getRequestResponsePanel());
    pane.setDividerLocation(250);
    pane.setResizeWeight(0.25D);//from www.  j av a  2  s .  c o  m
    ret.add(BorderLayout.CENTER, pane);
    return ret;
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(400, 400);//  w w  w  .ja  v a  2 s  . c  om
    JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    split.setDividerLocation(200);
    add(split);

    JPanel panel1 = new JPanel();
    panel1.setLayout(new BorderLayout());
    panel1.add(new JLabel("top panel"), BorderLayout.NORTH);

    JPanel myDrawPanel = new JPanel();
    myDrawPanel.setPreferredSize(new Dimension(100, 100));
    myDrawPanel.add(new JLabel("draw panel here!"));
    panel1.add(new JScrollPane(myDrawPanel), BorderLayout.CENTER);

    split.setTopComponent(panel1);

    JPanel panel2 = new JPanel();
    panel2.add(new JLabel("bottom panel"));
    split.setBottomComponent(panel2);
    setVisible(true);
}

From source file:gchisto.gui.panels.gcdistribution.ChartPanelAll.java

/**
 * It creates a chart for the given dataset and adds the chart to the panel.
 *
 * @param dataset The dataset that will provide the values for the chart.
 *//*from w w w. j  a v  a 2  s .  c  om*/
private void addChart(XYDatasetWithGroups dataset) {
    assert dataset != null;

    JFreeChart chart = ChartFactory.createXYAreaChart(getTitle(), "Buckets (sec)", "Count", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    // null so that we can get it compiled; we'll get back to this...
    GroupActivatingPanel table = new GroupActivatingPanel(dataset, null);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, table,
            new org.jfree.chart.ChartPanel(chart));
    splitPane.setDividerLocation(200);
    mainPanel().add(BorderLayout.CENTER, splitPane);
}

From source file:commonline.query.gui.Frame.java

private void initializeView(ExecuteScriptAction executeScriptAction, Action stopScriptAction) {
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new DatabaseStructurePanel(),
            new QueryPanel(executeScriptAction, stopScriptAction));
    split.setDividerLocation(200);

    getContentPane().add(split, BorderLayout.CENTER);
}