Demo: "Data components" tab: added checkboxes to control table grid and selection

This commit is contained in:
Karl Tauber
2020-09-03 11:53:50 +02:00
parent c78c653b0a
commit e945f46f25
2 changed files with 190 additions and 21 deletions

View File

@@ -16,6 +16,9 @@
package com.formdev.flatlaf.demo; 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.DataFlavor;
import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable; 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" } ) @SuppressWarnings( { "unchecked", "rawtypes" } )
private void initComponents() { private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
@@ -80,6 +118,13 @@ class DataComponentsPanel
JLabel tableLabel = new JLabel(); JLabel tableLabel = new JLabel();
JScrollPane scrollPane5 = new JScrollPane(); JScrollPane scrollPane5 = new JScrollPane();
table1 = new JTable(); 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(); dndCheckBox = new JCheckBox();
JPopupMenu popupMenu2 = new JPopupMenu(); JPopupMenu popupMenu2 = new JPopupMenu();
JMenuItem menuItem3 = new JMenuItem(); JMenuItem menuItem3 = new JMenuItem();
@@ -93,12 +138,12 @@ class DataComponentsPanel
// columns // columns
"[]" + "[]" +
"[200,fill]" + "[200,fill]" +
"[200,fill]", "[200,fill]" +
"[fill]",
// rows // rows
"[150,grow,sizegroup 1,fill]" + "[150,grow,sizegroup 1,fill]" +
"[150,grow,sizegroup 1,fill]" + "[150,grow,sizegroup 1,fill]" +
"[150,grow,sizegroup 1,fill]" + "[150,grow,sizegroup 1,fill]"));
"[]"));
//---- listLabel ---- //---- listLabel ----
listLabel.setText("JList:"); listLabel.setText("JList:");
@@ -299,11 +344,59 @@ class DataComponentsPanel
} }
add(scrollPane5, "cell 1 2 2 1,width 300"); add(scrollPane5, "cell 1 2 2 1,width 300");
//---- dndCheckBox ---- //======== tableOptionsPanel ========
dndCheckBox.setText("enable drag and drop"); {
dndCheckBox.setMnemonic('D'); tableOptionsPanel.setLayout(new MigLayout(
dndCheckBox.addActionListener(e -> dndChanged()); "insets 0,hidemode 3",
add(dndCheckBox, "cell 0 3 3 1"); // 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 ======== //======== popupMenu2 ========
{ {
@@ -336,6 +429,12 @@ class DataComponentsPanel
private JTree tree1; private JTree tree1;
private JTree tree2; private JTree tree2;
private JTable table1; private JTable table1;
private JCheckBox showHorizontalLinesCheckBox;
private JCheckBox showVerticalLinesCheckBox;
private JCheckBox intercellSpacingCheckBox;
private JCheckBox redGridColorCheckBox;
private JCheckBox rowSelectionCheckBox;
private JCheckBox columnSelectionCheckBox;
private JCheckBox dndCheckBox; private JCheckBox dndCheckBox;
// JFormDesigner - End of variables declaration //GEN-END:variables // JFormDesigner - End of variables declaration //GEN-END:variables

View File

@@ -8,8 +8,8 @@ new FormModel {
} }
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets dialog,hidemode 3" "$layoutConstraints": "insets dialog,hidemode 3"
"$columnConstraints": "[][200,fill][200,fill]" "$columnConstraints": "[][200,fill][200,fill][fill]"
"$rowConstraints": "[150,grow,sizegroup 1,fill][150,grow,sizegroup 1,fill][150,grow,sizegroup 1,fill][]" "$rowConstraints": "[150,grow,sizegroup 1,fill][150,grow,sizegroup 1,fill][150,grow,sizegroup 1,fill]"
} ) { } ) {
name: "this" name: "this"
add( new FormComponent( "javax.swing.JLabel" ) { add( new FormComponent( "javax.swing.JLabel" ) {
@@ -309,20 +309,90 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2 2 1,width 300" "value": "cell 1 2 2 1,width 300"
} ) } )
add( new FormComponent( "javax.swing.JCheckBox" ) { add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
name: "dndCheckBox" "$layoutConstraints": "insets 0,hidemode 3"
"text": "enable drag and drop" "$columnConstraints": "[]"
"mnemonic": 68 "$rowConstraints": "[]0[]0[]0[]0[]0[]0[]0"
auxiliary() { } ) {
"JavaCodeGenerator.variableLocal": false name: "tableOptionsPanel"
} add( new FormComponent( "javax.swing.JCheckBox" ) {
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "dndChanged", false ) ) 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 ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 3 3 1" "value": "cell 3 2"
} ) } )
}, new FormLayoutConstraints( null ) { }, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 ) "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 ) ) { add( new FormContainer( "javax.swing.JPopupMenu", new FormLayoutManager( class javax.swing.JPopupMenu ) ) {
name: "popupMenu2" name: "popupMenu2"
@@ -346,7 +416,7 @@ new FormModel {
"text": "Noop Action" "text": "Noop Action"
} ) } )
}, new FormLayoutConstraints( null ) { }, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 740 ) "location": new java.awt.Point( 0, 800 )
} ) } )
} }
} }