Search code examples
javaswingborder

JSplitPane set resizable false


How to make JSplitPane to resizable false? I didn't want to resize the JSplitPane, I used it for the border of this pane. Is there any other way to create same border structure to split a panel vertically into two parts.


Solution

  • You can override the JSplitPane methodes getDividerLocation() and getLastDividerLocation and return a constant value.

    JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT){
        private final int location = 100;
        {
            setDividerLocation( location );
        }
        @Override
        public int getDividerLocation() {
            return location ;
        }
        @Override
        public int getLastDividerLocation() {
            return location ;
        }
    };