diff --git a/CHANGELOG.md b/CHANGELOG.md index e9120fb5..0abc5f73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ FlatLaf Change Log `JButton.buttonType` to `underline`). - Button and TextComponent: Support per component minimum width (set client property `JComponent.minimumWidth` to an integer). +- ScrollPane with Table: The border of buttons that are added to one of the four + scroll pane corners are now removed if the center component is a table. Also, + these corner buttons are made not focusable. ## 0.23.1 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java index 84fc4583..31481542 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java @@ -25,11 +25,15 @@ import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import javax.swing.BorderFactory; +import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JScrollBar; import javax.swing.JScrollPane; +import javax.swing.JTable; import javax.swing.JViewport; import javax.swing.LookAndFeel; +import javax.swing.ScrollPaneConstants; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicScrollPaneUI; @@ -97,17 +101,35 @@ public class FlatScrollPaneUI public void propertyChange( PropertyChangeEvent e ) { super.propertyChange( e ); - if( FlatClientProperties.SCROLL_BAR_SHOW_BUTTONS.equals( e.getPropertyName() ) ) { - JScrollBar vsb = scrollpane.getVerticalScrollBar(); - JScrollBar hsb = scrollpane.getHorizontalScrollBar(); - if( vsb != null ) { - vsb.revalidate(); - vsb.repaint(); - } - if( hsb != null ) { - hsb.revalidate(); - hsb.repaint(); - } + switch( e.getPropertyName() ) { + case FlatClientProperties.SCROLL_BAR_SHOW_BUTTONS: + JScrollBar vsb = scrollpane.getVerticalScrollBar(); + JScrollBar hsb = scrollpane.getHorizontalScrollBar(); + if( vsb != null ) { + vsb.revalidate(); + vsb.repaint(); + } + if( hsb != null ) { + hsb.revalidate(); + hsb.repaint(); + } + break; + + case ScrollPaneConstants.LOWER_LEFT_CORNER: + case ScrollPaneConstants.LOWER_RIGHT_CORNER: + case ScrollPaneConstants.UPPER_LEFT_CORNER: + case ScrollPaneConstants.UPPER_RIGHT_CORNER: + // remove border from buttons added to corners + Object corner = e.getNewValue(); + if( corner instanceof JButton && + ((JButton)corner).getBorder() instanceof FlatButtonBorder && + scrollpane.getViewport() != null && + scrollpane.getViewport().getView() instanceof JTable ) + { + ((JButton)corner).setBorder( BorderFactory.createEmptyBorder() ); + ((JButton)corner).setFocusable( false ); + } + break; } } }; diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.java index f050e511..56d3f67c 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.java @@ -21,6 +21,7 @@ import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; import javax.swing.*; import javax.swing.table.*; +import com.formdev.flatlaf.icons.FlatMenuArrowIcon; import net.miginfocom.swing.*; /** @@ -70,6 +71,18 @@ public class FlatComponents2Test } } + private void tableHeaderButtonChanged() { + boolean show = tableHeaderButtonCheckBox.isSelected(); + JButton button = null; + if( show ) { + button = new JButton( new FlatMenuArrowIcon() ); + button.addActionListener( e -> { + JOptionPane.showMessageDialog( this, "hello" ); + } ); + } + scrollPane5.setCorner( JScrollPane.UPPER_TRAILING_CORNER, button ); + } + @SuppressWarnings( { "unchecked", "rawtypes" } ) private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents @@ -87,9 +100,10 @@ public class FlatComponents2Test JScrollPane scrollPane4 = new JScrollPane(); tree2 = new JTree(); JLabel tableLabel = new JLabel(); - JScrollPane scrollPane5 = new JScrollPane(); + scrollPane5 = new JScrollPane(); table1 = new JTable(); dndCheckBox = new JCheckBox(); + tableHeaderButtonCheckBox = new JCheckBox(); //======== this ======== setLayout(new MigLayout( @@ -102,7 +116,7 @@ public class FlatComponents2Test "[]" + "[]" + "[::200]" + - "[::150]" + + "[150,grow]" + "[]")); //---- textFieldLabel ---- @@ -293,6 +307,11 @@ public class FlatComponents2Test dndCheckBox.setMnemonic('D'); dndCheckBox.addActionListener(e -> dndChanged()); add(dndCheckBox, "cell 0 4 3 1"); + + //---- tableHeaderButtonCheckBox ---- + tableHeaderButtonCheckBox.setText("show button in table header"); + tableHeaderButtonCheckBox.addActionListener(e -> tableHeaderButtonChanged()); + add(tableHeaderButtonCheckBox, "cell 0 4 3 1"); // JFormDesigner - End of component initialization //GEN-END:initComponents ((JComboBox)((DefaultCellEditor)table1.getColumnModel().getColumn( 3 ).getCellEditor()).getComponent()).setEditable( true ); @@ -303,8 +322,10 @@ public class FlatComponents2Test private JList list2; private JTree tree1; private JTree tree2; + private JScrollPane scrollPane5; private JTable table1; private JCheckBox dndCheckBox; + private JCheckBox tableHeaderButtonCheckBox; // JFormDesigner - End of variables declaration //GEN-END:variables //---- class DummyTransferHandler ----------------------------------------- diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.jfd index 62f281b8..7b992ea7 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.jfd @@ -1,4 +1,4 @@ -JFDML JFormDesigner: "7.0.0.0.194" Java: "11.0.2" encoding: "UTF-8" +JFDML JFormDesigner: "7.0.0.0.194" Java: "13.0.1" encoding: "UTF-8" new FormModel { contentType: "form/swing" @@ -9,7 +9,7 @@ new FormModel { add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$layoutConstraints": "ltr,insets dialog,hidemode 3" "$columnConstraints": "[][200][200]" - "$rowConstraints": "[][][::200][::150][]" + "$rowConstraints": "[][][::200][150,grow][]" } ) { name: "this" add( new FormComponent( "javax.swing.JLabel" ) { @@ -135,6 +135,9 @@ new FormModel { } ) add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { name: "scrollPane5" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } add( new FormComponent( "javax.swing.JTable" ) { name: "table1" "model": new com.jformdesigner.model.SwingTableModel( new java.util.Vector { @@ -282,6 +285,16 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 0 4 3 1" } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "tableHeaderButtonCheckBox" + "text": "show button in table header" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "tableHeaderButtonChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 4 3 1" + } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 ) "size": new java.awt.Dimension( 790, 715 )