diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DataComponentsPanel.java b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DataComponentsPanel.java index d5ab79db..41860d45 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DataComponentsPanel.java +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DataComponentsPanel.java @@ -16,6 +16,9 @@ package com.formdev.flatlaf.demo; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.EventQueue; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; @@ -64,6 +67,41 @@ class DataComponentsPanel } } + private void rowSelectionChanged() { + table1.setRowSelectionAllowed( rowSelectionCheckBox.isSelected() ); + } + + private void columnSelectionChanged() { + table1.setColumnSelectionAllowed( columnSelectionCheckBox.isSelected() ); + } + + private void showHorizontalLinesChanged() { + table1.setShowHorizontalLines( showHorizontalLinesCheckBox.isSelected() ); + } + + private void showVerticalLinesChanged() { + table1.setShowVerticalLines( showVerticalLinesCheckBox.isSelected() ); + } + + private void intercellSpacingChanged() { + table1.setIntercellSpacing( intercellSpacingCheckBox.isSelected() ? new Dimension( 1, 1 ) : new Dimension() ); + } + + private void redGridColorChanged() { + table1.setGridColor( redGridColorCheckBox.isSelected() ? Color.red : UIManager.getColor( "Table.gridColor" ) ); + } + + @Override + public void updateUI() { + super.updateUI(); + + EventQueue.invokeLater( () -> { + showHorizontalLinesChanged(); + showVerticalLinesChanged(); + intercellSpacingChanged(); + } ); + } + @SuppressWarnings( { "unchecked", "rawtypes" } ) private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents @@ -80,6 +118,13 @@ class DataComponentsPanel JLabel tableLabel = new JLabel(); JScrollPane scrollPane5 = new JScrollPane(); table1 = new JTable(); + JPanel tableOptionsPanel = new JPanel(); + showHorizontalLinesCheckBox = new JCheckBox(); + showVerticalLinesCheckBox = new JCheckBox(); + intercellSpacingCheckBox = new JCheckBox(); + redGridColorCheckBox = new JCheckBox(); + rowSelectionCheckBox = new JCheckBox(); + columnSelectionCheckBox = new JCheckBox(); dndCheckBox = new JCheckBox(); JPopupMenu popupMenu2 = new JPopupMenu(); JMenuItem menuItem3 = new JMenuItem(); @@ -93,12 +138,12 @@ class DataComponentsPanel // columns "[]" + "[200,fill]" + - "[200,fill]", + "[200,fill]" + + "[fill]", // rows "[150,grow,sizegroup 1,fill]" + "[150,grow,sizegroup 1,fill]" + - "[150,grow,sizegroup 1,fill]" + - "[]")); + "[150,grow,sizegroup 1,fill]")); //---- listLabel ---- listLabel.setText("JList:"); @@ -299,11 +344,59 @@ class DataComponentsPanel } add(scrollPane5, "cell 1 2 2 1,width 300"); - //---- dndCheckBox ---- - dndCheckBox.setText("enable drag and drop"); - dndCheckBox.setMnemonic('D'); - dndCheckBox.addActionListener(e -> dndChanged()); - add(dndCheckBox, "cell 0 3 3 1"); + //======== tableOptionsPanel ======== + { + tableOptionsPanel.setLayout(new MigLayout( + "insets 0,hidemode 3", + // columns + "[]", + // rows + "[]0" + + "[]0" + + "[]0" + + "[]0" + + "[]0" + + "[]0" + + "[]0")); + + //---- showHorizontalLinesCheckBox ---- + showHorizontalLinesCheckBox.setText("show horizontal lines"); + showHorizontalLinesCheckBox.addActionListener(e -> showHorizontalLinesChanged()); + tableOptionsPanel.add(showHorizontalLinesCheckBox, "cell 0 0"); + + //---- showVerticalLinesCheckBox ---- + showVerticalLinesCheckBox.setText("show vertical lines"); + showVerticalLinesCheckBox.addActionListener(e -> showVerticalLinesChanged()); + tableOptionsPanel.add(showVerticalLinesCheckBox, "cell 0 1"); + + //---- intercellSpacingCheckBox ---- + intercellSpacingCheckBox.setText("intercell spacing"); + intercellSpacingCheckBox.addActionListener(e -> intercellSpacingChanged()); + tableOptionsPanel.add(intercellSpacingCheckBox, "cell 0 2"); + + //---- redGridColorCheckBox ---- + redGridColorCheckBox.setText("red grid color"); + redGridColorCheckBox.addActionListener(e -> redGridColorChanged()); + tableOptionsPanel.add(redGridColorCheckBox, "cell 0 3"); + + //---- rowSelectionCheckBox ---- + rowSelectionCheckBox.setText("row selection"); + rowSelectionCheckBox.setSelected(true); + rowSelectionCheckBox.addActionListener(e -> rowSelectionChanged()); + tableOptionsPanel.add(rowSelectionCheckBox, "cell 0 4"); + + //---- columnSelectionCheckBox ---- + columnSelectionCheckBox.setText("column selection"); + columnSelectionCheckBox.addActionListener(e -> columnSelectionChanged()); + tableOptionsPanel.add(columnSelectionCheckBox, "cell 0 5"); + + //---- dndCheckBox ---- + dndCheckBox.setText("enable drag and drop"); + dndCheckBox.setMnemonic('D'); + dndCheckBox.addActionListener(e -> dndChanged()); + tableOptionsPanel.add(dndCheckBox, "cell 0 6"); + } + add(tableOptionsPanel, "cell 3 2"); //======== popupMenu2 ======== { @@ -336,6 +429,12 @@ class DataComponentsPanel private JTree tree1; private JTree tree2; private JTable table1; + private JCheckBox showHorizontalLinesCheckBox; + private JCheckBox showVerticalLinesCheckBox; + private JCheckBox intercellSpacingCheckBox; + private JCheckBox redGridColorCheckBox; + private JCheckBox rowSelectionCheckBox; + private JCheckBox columnSelectionCheckBox; private JCheckBox dndCheckBox; // JFormDesigner - End of variables declaration //GEN-END:variables diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DataComponentsPanel.jfd b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DataComponentsPanel.jfd index 7f06c857..5da120b1 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DataComponentsPanel.jfd +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DataComponentsPanel.jfd @@ -8,8 +8,8 @@ new FormModel { } add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$layoutConstraints": "insets dialog,hidemode 3" - "$columnConstraints": "[][200,fill][200,fill]" - "$rowConstraints": "[150,grow,sizegroup 1,fill][150,grow,sizegroup 1,fill][150,grow,sizegroup 1,fill][]" + "$columnConstraints": "[][200,fill][200,fill][fill]" + "$rowConstraints": "[150,grow,sizegroup 1,fill][150,grow,sizegroup 1,fill][150,grow,sizegroup 1,fill]" } ) { name: "this" add( new FormComponent( "javax.swing.JLabel" ) { @@ -309,20 +309,90 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 2 2 1,width 300" } ) - add( new FormComponent( "javax.swing.JCheckBox" ) { - name: "dndCheckBox" - "text": "enable drag and drop" - "mnemonic": 68 - auxiliary() { - "JavaCodeGenerator.variableLocal": false - } - addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "dndChanged", false ) ) + add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { + "$layoutConstraints": "insets 0,hidemode 3" + "$columnConstraints": "[]" + "$rowConstraints": "[]0[]0[]0[]0[]0[]0[]0" + } ) { + name: "tableOptionsPanel" + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "showHorizontalLinesCheckBox" + "text": "show horizontal lines" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showHorizontalLinesChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 0" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "showVerticalLinesCheckBox" + "text": "show vertical lines" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showVerticalLinesChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 1" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "intercellSpacingCheckBox" + "text": "intercell spacing" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "intercellSpacingChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 2" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "redGridColorCheckBox" + "text": "red grid color" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "redGridColorChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 3" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "rowSelectionCheckBox" + "text": "row selection" + "selected": true + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "rowSelectionChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 4" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "columnSelectionCheckBox" + "text": "column selection" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "columnSelectionChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 5" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "dndCheckBox" + "text": "enable drag and drop" + "mnemonic": 68 + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "dndChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 6" + } ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 3 3 1" + "value": "cell 3 2" } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 ) - "size": new java.awt.Dimension( 790, 715 ) + "size": new java.awt.Dimension( 790, 745 ) } ) add( new FormContainer( "javax.swing.JPopupMenu", new FormLayoutManager( class javax.swing.JPopupMenu ) ) { name: "popupMenu2" @@ -346,7 +416,7 @@ new FormModel { "text": "Noop Action" } ) }, new FormLayoutConstraints( null ) { - "location": new java.awt.Point( 0, 740 ) + "location": new java.awt.Point( 0, 800 ) } ) } }