Skip to content

Commit ce9e526

Browse files
author
java-tester-x
committed
GUI: splitPane example
1 parent d7aef0a commit ce9e526

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

gui/SplitPaneDemo2.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,25 @@ public class SplitPaneDemo2 extends JFrame {
2222

2323
private AbstractDocument doc;
2424

25-
private JTextPane textPane;
26-
private JTextArea changeLog;
27-
private JLabel label;
25+
private JTextPane sqlTextPane;
26+
private JEditorPane lessonTextPane;
27+
private JTextArea changeLog;
28+
private JLabel label;
2829

2930
public SplitPaneDemo2() {
3031
super("SplitPaneDemo2");
3132

32-
textPane = new JTextPane();
33-
textPane.setCaretPosition(0);
34-
textPane.setMargin(new Insets(5,5,5,5));
35-
StyledDocument styledDoc = textPane.getStyledDocument();
33+
sqlTextPane = new JTextPane();
34+
sqlTextPane.setCaretPosition(0);
35+
sqlTextPane.setMargin(new Insets(5,5,5,5));
36+
StyledDocument styledDoc = sqlTextPane.getStyledDocument();
3637
if (styledDoc instanceof AbstractDocument) {
3738
doc = (AbstractDocument)styledDoc;
3839
} else {
3940
System.err.println("Text pane's document isn't an AbstractDocument!");
4041
System.exit(-1);
4142
}
42-
JScrollPane scrollPane = new JScrollPane(textPane);
43+
JScrollPane scrollPane = new JScrollPane(sqlTextPane);
4344
scrollPane.setPreferredSize(new Dimension(200, 200));
4445

4546
//Create the text area for the status log and configure it.
@@ -48,30 +49,32 @@ public SplitPaneDemo2() {
4849
JScrollPane scrollPaneForLog = new JScrollPane(changeLog);
4950

5051
//Create a split pane for the change log and the text area.
51-
JSplitPane leftPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollPane, scrollPaneForLog);
52+
JSplitPane leftPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog);
5253
leftPane.setOneTouchExpandable(true);
5354

54-
55+
//Provide minimum sizes for the two components in the split pane
56+
leftPane.setMinimumSize(new Dimension(100, 50));
5557

5658
//XXXX: Bug #4131528, borders on nested split panes accumulate.
5759
//Workaround: Set the border on any split pane within
5860
//another split pane to null. Components within nested split
5961
//panes need to have their own border for this to work well.
6062
leftPane.setBorder(null);
6163

62-
//Create a regular old label
63-
label = new JLabel("Click on an image name in the list.", JLabel.CENTER);
64+
lessonTextPane = new JEditorPane();
65+
lessonTextPane.setEditable(false);
66+
lessonTextPane.setCaretPosition(0);
67+
lessonTextPane.setMargin(new Insets(5,5,5,5));
68+
69+
JScrollPane scrollPaneForLesson = new JScrollPane(lessonTextPane);
70+
scrollPaneForLesson.setPreferredSize(new Dimension(200, 200));
6471

6572
//Create a split pane and put "top" (a split pane)
6673
//and JLabel instance in it.
67-
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, leftPane, label);
74+
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPane, scrollPaneForLesson);
6875
splitPane.setOneTouchExpandable(true);
6976
splitPane.setDividerLocation(180);
7077

71-
//Provide minimum sizes for the two components in the split pane
72-
// leftPane.setMinimumSize(new Dimension(100, 50));
73-
label.setMinimumSize(new Dimension(100, 30));
74-
7578
//Add the split pane to this frame
7679
getContentPane().add(splitPane);
7780
}

0 commit comments

Comments
 (0)