Mega Code Archive

 
Categories / Java / Swing JFC
 

Getting and Setting the Divider Location in a JSplitPane Container

import javax.swing.JButton; import javax.swing.JSplitPane; public class Main {   public static void main(String[] argv) throws Exception {     JButton leftComponent = new JButton("left");     JButton rightComponent = new JButton("right");     JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftComponent, rightComponent);     int loc = pane.getDividerLocation();     loc = (int) ((pane.getBounds().getWidth() - pane.getDividerSize()) / 2);     pane.setDividerLocation(loc);     double propLoc = .5D;     pane.setDividerLocation(propLoc);   } }