Use of jsplitpane

Source: Internet
Author: User

Java. Lang. Object
-- Java. AWT. Component
-- Java. AWT. Container
-- Javax. Swing. jcomponent
-- Javax. Swing. jsplitpane
Split pane displays two components in two display zones at a time. If you want to display components in multiple display zones at the same time, you must make
Use multiple split pane. Jsplitpane provides two constants for you to determine whether horizontal or vertical segmentation is required. The two constants are: horizontal_spit,
Vertical_split. In addition to the two important constants, jsplitpane also provides many class constants for you to use. We will introduce common class constants in the following example.
For other information, see Java API.
Jsplitpane constructor:
Jsplitpane (): Creates a new jsplitpane, which contains two default buttons and arranged horizontally. This does not support the continuous layout function.
Jsplitpane (INT neworientation): Creates a specified horizontal or vertical cutting jsplitpane, but does not have the continuous layout function.
Jsplitpnae (INT neworientation, Boolean newcontinuouslayout): Creates a jsplitpane with a specified horizontal or vertical cut and specifies whether
Has the continuous layout function.
Jsplitpane (INT neworientation, Boolean newcontinuouslayout, component newleftcomponent, component newrightcomponent ):
Create a jsplitpane for horizontal or vertical cutting, specify the components to be displayed in the display area, and set whether to continue
Layout function.
Jsplitpane (INT neworientation, component newleftcomponent, component newrightcomponent ):
Create a jsplitpane with a specified horizontal or vertical cutting and specify the components to be displayed in the display area. However, the continuous layout function is not available.
.
The continuous layout mentioned above indicates whether the components in the window dynamically change the size when you drag the separator line of the cut panel.
. Newcontinuouslayout is a Boolean value. If it is set to true, the component size will be changed along with the drag of the separator line;
If it is set to false, the component size is determined only when the separator line is stopped. You can also use the setcontinuouslayout () method in jsplitpane to set this project.

Example of jsplitpane: jsplitpane1.java

Import java. AWT .*;
Import java. AWT. event .*;
Import javax. Swing .*;

Public class jsplitpane1 {
Public jsplitpane1 (){
Jframe F = new jframe ("jsplitpanedemo ");
Container contentpane = f. getcontentpane ();
Jlabel label1 = new jlabel ("label 1", jlabel. center );
Label1.setbackground (color. Green );
Label1.setopaque (true); // The setopaqueiture method is used to make the component become opaque, so that the color we set on the jlabel
// To be displayed.
Jlabel label2 = new jlabel ("label 2", jlabel. center );
Label2.setbackground (color. Pink );
Label2.setopaque (true );

Jlabel label3 = new jlabel ("label 3", jlabel. center );
Label3.setbackground (color. Yellow );
Label3.setopaque (true );
/* Add label1, label2 to splitpane1, and set this splitpane1 to horizontally split with continuous Layout
* Function.
*/
Jsplitpane splitpane1 = new jsplitpane (jsplitpane. horizontal_split, false, label1, label2 );
/* Set the separator position of splitpane1. The value 0.3 is determined by the size of splitpane1. Therefore, the value range is between 0.0 and ~ 1.0
. If you use an integer to set the separator position of splitpane, as shown in row 34th, the defined value is calculated in pixel.
*/
Splitpane1.setdividerlocation (0.3 );
/* Set whether jsplitpane can be expanded or collapsed (like a File Manager). If it is set to true, this function is enabled.
*/
Splitpane1.setonetouchexpandable (true );
Splitpane1.setdividersize (10); // set the size of the separator line width, in pixel.

Jsplitpane splitpane2 = new jsplitpane (jsplitpane. vertical_split, false, splitpane1, label3 );
Splitpane2.setdividerlocation (35 );
// Sets whether jsplitpane can be expanded or collapsed (as in the case of a file manager). If it is set to true, this function is enabled.
Splitpane2.setonetouchexpandable (false );
Splitpane2.setdividersize (5 );

Contentpane. Add (splitpane2 );

F. setsize (250,200 );
F. Show ();
F. addwindowlistener (
New windowadapter (){
Public void windowclosing (windowevent e ){
System. Exit (0 );
}
}
);
}
Public static void main (string [] ARGs ){
New jsplitpane1 ();
}
}

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.