zoukankan      html  css  js  c++  java
  • e826. 获得和设置JSplitPane分开的位置

    The location of a divider is measured in pixels from either the left edge (in the case of a horizontal split pane) or the top edge (in the case of a vertical split pane).

    There are two ways to set the location of the divider. The first is to specify an absolute location based on the distance in pixels from the left or top edge. The second is to specify a proportional location based on the distance from the left or top edge. For example, a proportional location of 0 sets the divider at the left or top edge. A proportional location of 1 sets the divider at the right or bottom edge. A proportional location of .5 sets the divider at the center.

        // Create a left-right split pane
        JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftComponent, rightComponent);
        
        // Get current location; result is number of pixels from the left edge
        int loc = pane.getDividerLocation();
        
        // Set a new location using an absolution location; center the divider
        loc = (int)((pane.getBounds().getWidth()-pane.getDividerSize())/2);
        pane.setDividerLocation(loc);
        
        double propLoc = .5D;
        // Set a proportional location
        pane.setDividerLocation(propLoc);
    
    Related Examples
  • 相关阅读:
    Singleton模式
    Factory模式
    AbstactFactory模式
    Maven的介绍及使用
    MySQL索引分析及使用
    Runnable接口和Callable接口的区别
    Java中的常见数学运算
    mkdir()和mkdirs()区别
    面试小问题——Object中有哪些常用方法?
    面试小问题——什么是多态?
  • 原文地址:https://www.cnblogs.com/borter/p/9596265.html
Copyright © 2011-2022 走看看