20 package net.sf.gridarta.gui.utils;
22 import java.awt.BorderLayout;
23 import java.awt.Color;
24 import java.awt.Dimension;
25 import java.awt.Window;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.lang.reflect.InvocationTargetException;
29 import javax.swing.AbstractButton;
30 import javax.swing.JButton;
31 import javax.swing.JFrame;
32 import javax.swing.JPanel;
33 import javax.swing.JSplitPane;
34 import javax.swing.SwingUtilities;
35 import org.jetbrains.annotations.NotNull;
62 public static void main(@NotNull
final String[] args)
throws InterruptedException, InvocationTargetException {
63 SwingUtilities.invokeAndWait(
new Runnable() {
67 final JPanel green =
newPanel(MIN_SIZE, MIN_SIZE, Color.GREEN);
68 final JPanel blue =
newPanel(MIN_SIZE, MIN_SIZE, Color.BLUE);
69 final JPanel yellow =
newPanel(MIN_SIZE, MIN_SIZE, Color.YELLOW);
70 final JPanel orange =
newPanel(MIN_SIZE, MIN_SIZE, Color.ORANGE);
71 final GSplitPane splitPane1 =
new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, green, blue,
"TEST_GREEN_BLUE", 70);
72 splitPane1.setResizeWeight(0.5);
73 final GSplitPane splitPane2 =
new GSplitPane(JSplitPane.VERTICAL_SPLIT, splitPane1, yellow,
"TEST_GREEN_BLUE_YELLOW", 40);
74 final GSplitPane splitPane3 =
new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, orange, splitPane2,
"TEST_ORANGE_GREEN_BLUE_YELLOW", 30);
75 final AbstractButton button =
new JButton(
"save divider locations and quit");
76 final Window frame =
new JFrame();
77 button.addActionListener(
new ActionListener() {
80 public void actionPerformed(@NotNull
final ActionEvent e) {
84 frame.setVisible(
false);
88 frame.setLayout(
new BorderLayout());
89 frame.add(button, BorderLayout.SOUTH);
90 frame.add(splitPane3);
92 frame.setSize(
new Dimension(800, 600));
93 frame.setLocationRelativeTo(null);
94 frame.setVisible(
true);
106 private static JPanel
newPanel(
final int width,
final int height, @NotNull
final Color color) {
107 final JPanel panel =
new JPanel();
108 panel.setMinimumSize(
new Dimension(width, height));
109 panel.setOpaque(
true);
110 panel.setBackground(color);
A JSplitPane that keeps its size even upon ancestor layout changes and is restored upon editor restar...
static final int MIN_SIZE
The minimal size of components.
GSplitPaneTestApplication()
Private constructor to prevent instantiation.
Simple application for testing GSplitPane behavior.
void saveLocation()
Saves the current divider location into the preferences.
static JPanel newPanel(final int width, final int height, @NotNull final Color color)
Creates a new colored area.
static void main(@NotNull final String[] args)
The entry point of the application.