summaryrefslogtreecommitdiff
path: root/base/src/examples/java
diff options
context:
space:
mode:
authorBenjamin Culkin <scorpress@gmail.com>2025-12-07 17:19:17 -0500
committerBenjamin Culkin <scorpress@gmail.com>2025-12-07 17:19:17 -0500
commit9955011dad278183c77dcebb74864ace8ad52e3c (patch)
treee5c9f1da67b8a604c939a4e77a2767116c8eb5ae /base/src/examples/java
parente8e15d0335c7252f78b71c59905cb82c8964e80a (diff)
Add a collapsible JPanel
Adds a collapsible version of a JPanel, useful in various places
Diffstat (limited to 'base/src/examples/java')
-rw-r--r--base/src/examples/java/bjc/utils/examples/gui/panels/CollapsiblePanelDemo.java71
1 files changed, 71 insertions, 0 deletions
diff --git a/base/src/examples/java/bjc/utils/examples/gui/panels/CollapsiblePanelDemo.java b/base/src/examples/java/bjc/utils/examples/gui/panels/CollapsiblePanelDemo.java
new file mode 100644
index 0000000..fed128f
--- /dev/null
+++ b/base/src/examples/java/bjc/utils/examples/gui/panels/CollapsiblePanelDemo.java
@@ -0,0 +1,71 @@
+package bjc.utils.examples.gui.panels;
+
+import java.awt.BorderLayout;
+import java.awt.GridLayout;
+import java.awt.Insets;
+
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+
+import bjc.utils.gui.panels.CollapsiblePanel;
+
+public class CollapsiblePanelDemo {
+ public static void main(String[] args) {
+ SwingUtilities.invokeLater(() -> {
+ try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception ignored) {}
+
+ JFrame frame = new JFrame("CollapsiblePanel Demo");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setLayout(new BorderLayout());
+
+ JPanel content = new JPanel();
+ content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
+
+ CollapsiblePanel section1 = new CollapsiblePanel("Search Options");
+ // Add some content
+ section1.add(new JLabel("Keyword:"));
+ section1.add(new JTextField(20));
+ section1.add(new JCheckBox("Case sensitive"));
+
+ // Add custom header bits (e.g. a small gear button)
+ JButton gear = new JButton("\u2699"); // ⚙
+ gear.setMargin(new Insets(0, 4, 0, 4));
+ gear.setFocusable(false);
+ section1.addHeaderComponent(gear);
+
+ CollapsiblePanel section2 = new CollapsiblePanel("Advanced Filters", new GridLayout(0, 2, 4, 4));
+ section2.add(new JLabel("From date:"));
+ section2.add(new JTextField(10));
+ section2.add(new JLabel("To date:"));
+ section2.add(new JTextField(10));
+ section2.add(new JLabel("Status:"));
+ section2.add(new JComboBox<>(new String[]{"Any", "Open", "Closed"}));
+ section2.setCollapsed(true); // start collapsed
+
+ // Example: a right-aligned "Reset" button in the header
+ JButton resetBtn = new JButton("Reset");
+ resetBtn.setMargin(new Insets(0, 6, 0, 6));
+ resetBtn.setFocusable(false);
+ section2.setHeaderComponent(resetBtn);
+
+ content.add(section1);
+ content.add(Box.createVerticalStrut(8));
+ content.add(section2);
+
+ frame.add(new JScrollPane(content), BorderLayout.CENTER);
+ frame.setSize(450, 300);
+ frame.setLocationRelativeTo(null);
+ frame.setVisible(true);
+ });
+ }
+}