JSplitPane use of Java Swing components

Source: Internet
Author: User

Use to arrange the JSplitPane.HORIZONTAL_SPLIT two left-to-right of the separator pane Component , or use JSplitPane.VERTICAL_SPLIT it to arrange it from top to bottom. Componentthe preferred way to change the size is to call setDividerLocation , which location is the new x or Y position, depending on JSplitPane the direction.

To be Component adjusted to its preferred size, it can be called resetToPreferredSizes .


1. Common construction methods

JSplitPane(): Creates a new that is configured to arrange its subcomponents horizontally, without a continuous layout, using two buttons for the component JSplitPane .

JSplitPane(int newOrientation): Creates a new one that is configured in the specified direction and has no continuous layout JSplitPane .

JSplitPane(int newOrientation, boolean newContinuousLayout): Creates a new one with the specified direction and redraw mode JSplitPane .

2. Common methods

setDividerLocation(double proportionalLocation): Sets the position of the separator bar to JSplitPane a percentage of the size.

setDividerLocation(int location): Sets the position of the separator bar.

setContinuousLayout(boolean newContinuousLayout): Sets the continuousLayout value of the property, in which the user is expected to cause the subassembly to be continuously re-displayed and layout subcomponents, this value must be true .

setDividerSize(int newSize): Sets the size of the separator bar.

getDividerLocation(): Returns the last value passed to setDividerLocation .

getDividerSize(): Returns the size of the separator bar.

setOneTouchExpandable(boolean newValue): Set oneTouchExpandable The value of the property so that JSplitPane a UI widget is available on the divider to quickly expand/collapse the separator bar, which must be true .

3. Example

Import Java.awt.borderlayout;import javax.swing.jframe;import javax.swing.jlabel;import Javax.swing.JSplitPane; public class Jsplitpanedemo extends JFrame {private static final long Serialversionuid = -3418853823231348095l;public JSPL Itpanedemo () {settitle ("split panel"); SetBounds (+, +, 375); Setdefaultcloseoperation (Jframe.exit_on_close); JSplitPane Hsplitpane = new JSplitPane (); hsplitpane.setdividerlocation (+); Getcontentpane (). Add (Hsplitpane, Borderlayout.center); Hsplitpane.setleftcomponent (New JLabel ("1")); JSplitPane Vsplitpane = new JSplitPane (jsplitpane.vertical_split); Vsplitpane.setleftcomponent (New JLabel ("2")); Vsplitpane.setrightcomponent (New JLabel ("3")); Vsplitpane.setdividerlocation (+); vsplitpane.setdividersize (8); Vsplitpane.setonetouchexpandable (True); Vsplitpane.setcontinuouslayout (true); Hsplitpane.setrightcomponent ( Vsplitpane);} public static void Main (string[] args) {//TODO auto-generated method Stubjsplitpanedemo instance = new Jsplitpanedemo (); I Nstance.setviSible (True);}} 
4. Results


JSplitPane use of Java Swing components

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.