mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-07 06:20:53 +03:00
Table: do not select text in cell editor when it gets focus (when JTable.surrendersFocusOnKeystroke is true) and TextComponent.selectAllOnFocusPolicy is once (the default) or always (issue #395)
This commit is contained in:
@@ -42,6 +42,10 @@ FlatLaf Change Log
|
|||||||
to issue #382; regression since fixing #330 in FlatLaf 1.4)
|
to issue #382; regression since fixing #330 in FlatLaf 1.4)
|
||||||
- Tree: Fixed editing cell issue with custom cell renderer and cell editor that
|
- Tree: Fixed editing cell issue with custom cell renderer and cell editor that
|
||||||
use same component for rendering and editing. (issue #385)
|
use same component for rendering and editing. (issue #385)
|
||||||
|
- Table: Do not select text in cell editor when it gets focus (when
|
||||||
|
`JTable.surrendersFocusOnKeystroke` is `true`) and
|
||||||
|
`TextComponent.selectAllOnFocusPolicy` is `once` (the default) or `always`.
|
||||||
|
(issue #395)
|
||||||
|
|
||||||
|
|
||||||
## 1.6.1
|
## 1.6.1
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ public class FlatCaret
|
|||||||
protected void selectAllOnFocusGained() {
|
protected void selectAllOnFocusGained() {
|
||||||
JTextComponent c = getComponent();
|
JTextComponent c = getComponent();
|
||||||
Document doc = c.getDocument();
|
Document doc = c.getDocument();
|
||||||
if( doc == null || !c.isEnabled() || !c.isEditable() )
|
if( doc == null || !c.isEnabled() || !c.isEditable() || FlatUIUtils.isCellEditor( c ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Object selectAllOnFocusPolicy = c.getClientProperty( SELECT_ALL_ON_FOCUS_POLICY );
|
Object selectAllOnFocusPolicy = c.getClientProperty( SELECT_ALL_ON_FOCUS_POLICY );
|
||||||
|
|||||||
@@ -330,6 +330,11 @@ public class FlatComponents2Test
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void focusCellEditorChanged() {
|
||||||
|
for( JTable table : allTables )
|
||||||
|
table.setSurrendersFocusOnKeystroke( focusCellEditorCheckBox.isSelected() );
|
||||||
|
}
|
||||||
|
|
||||||
private void treeRendererChanged() {
|
private void treeRendererChanged() {
|
||||||
Object sel = treeRendererComboBox.getSelectedItem();
|
Object sel = treeRendererComboBox.getSelectedItem();
|
||||||
if( !(sel instanceof String) )
|
if( !(sel instanceof String) )
|
||||||
@@ -477,6 +482,7 @@ public class FlatComponents2Test
|
|||||||
sortIconPositionComboBox = new JComboBox<>();
|
sortIconPositionComboBox = new JComboBox<>();
|
||||||
showHorizontalLinesCheckBox = new JCheckBox();
|
showHorizontalLinesCheckBox = new JCheckBox();
|
||||||
rowSelectionCheckBox = new JCheckBox();
|
rowSelectionCheckBox = new JCheckBox();
|
||||||
|
focusCellEditorCheckBox = new JCheckBox();
|
||||||
showVerticalLinesCheckBox = new JCheckBox();
|
showVerticalLinesCheckBox = new JCheckBox();
|
||||||
columnSelectionCheckBox = new JCheckBox();
|
columnSelectionCheckBox = new JCheckBox();
|
||||||
intercellSpacingCheckBox = new JCheckBox();
|
intercellSpacingCheckBox = new JCheckBox();
|
||||||
@@ -490,7 +496,7 @@ public class FlatComponents2Test
|
|||||||
// columns
|
// columns
|
||||||
"[]" +
|
"[]" +
|
||||||
"[200,grow,sizegroup 1,fill]" +
|
"[200,grow,sizegroup 1,fill]" +
|
||||||
"[200,grow,sizegroup 1,fill]" +
|
"[200,grow,sizegroup 1,fill]para" +
|
||||||
"[fill]" +
|
"[fill]" +
|
||||||
"[200,grow,sizegroup 1,fill]" +
|
"[200,grow,sizegroup 1,fill]" +
|
||||||
"[200,grow,sizegroup 1,fill]",
|
"[200,grow,sizegroup 1,fill]",
|
||||||
@@ -790,6 +796,7 @@ public class FlatComponents2Test
|
|||||||
"hidemode 3",
|
"hidemode 3",
|
||||||
// columns
|
// columns
|
||||||
"[]" +
|
"[]" +
|
||||||
|
"[fill]" +
|
||||||
"[fill]",
|
"[fill]",
|
||||||
// rows
|
// rows
|
||||||
"[]" +
|
"[]" +
|
||||||
@@ -800,7 +807,7 @@ public class FlatComponents2Test
|
|||||||
|
|
||||||
//---- autoResizeModeLabel ----
|
//---- autoResizeModeLabel ----
|
||||||
autoResizeModeLabel.setText("Auto resize mode:");
|
autoResizeModeLabel.setText("Auto resize mode:");
|
||||||
tableOptionsPanel.add(autoResizeModeLabel, "cell 0 0 2 1");
|
tableOptionsPanel.add(autoResizeModeLabel, "cell 0 0 3 1");
|
||||||
|
|
||||||
//---- autoResizeModeField ----
|
//---- autoResizeModeField ----
|
||||||
autoResizeModeField.setModel(new DefaultComboBoxModel<>(new String[] {
|
autoResizeModeField.setModel(new DefaultComboBoxModel<>(new String[] {
|
||||||
@@ -812,11 +819,11 @@ public class FlatComponents2Test
|
|||||||
}));
|
}));
|
||||||
autoResizeModeField.setSelectedIndex(2);
|
autoResizeModeField.setSelectedIndex(2);
|
||||||
autoResizeModeField.addActionListener(e -> autoResizeModeChanged());
|
autoResizeModeField.addActionListener(e -> autoResizeModeChanged());
|
||||||
tableOptionsPanel.add(autoResizeModeField, "cell 0 0 2 1");
|
tableOptionsPanel.add(autoResizeModeField, "cell 0 0 3 1");
|
||||||
|
|
||||||
//---- sortIconPositionLabel ----
|
//---- sortIconPositionLabel ----
|
||||||
sortIconPositionLabel.setText("Sort icon:");
|
sortIconPositionLabel.setText("Sort icon:");
|
||||||
tableOptionsPanel.add(sortIconPositionLabel, "cell 0 0 2 1");
|
tableOptionsPanel.add(sortIconPositionLabel, "cell 0 0 3 1");
|
||||||
|
|
||||||
//---- sortIconPositionComboBox ----
|
//---- sortIconPositionComboBox ----
|
||||||
sortIconPositionComboBox.setModel(new DefaultComboBoxModel<>(new String[] {
|
sortIconPositionComboBox.setModel(new DefaultComboBoxModel<>(new String[] {
|
||||||
@@ -826,7 +833,7 @@ public class FlatComponents2Test
|
|||||||
"bottom"
|
"bottom"
|
||||||
}));
|
}));
|
||||||
sortIconPositionComboBox.addActionListener(e -> sortIconPositionChanged());
|
sortIconPositionComboBox.addActionListener(e -> sortIconPositionChanged());
|
||||||
tableOptionsPanel.add(sortIconPositionComboBox, "cell 0 0 2 1");
|
tableOptionsPanel.add(sortIconPositionComboBox, "cell 0 0 3 1");
|
||||||
|
|
||||||
//---- showHorizontalLinesCheckBox ----
|
//---- showHorizontalLinesCheckBox ----
|
||||||
showHorizontalLinesCheckBox.setText("show horizontal lines");
|
showHorizontalLinesCheckBox.setText("show horizontal lines");
|
||||||
@@ -839,6 +846,11 @@ public class FlatComponents2Test
|
|||||||
rowSelectionCheckBox.addActionListener(e -> rowSelectionChanged());
|
rowSelectionCheckBox.addActionListener(e -> rowSelectionChanged());
|
||||||
tableOptionsPanel.add(rowSelectionCheckBox, "cell 1 1");
|
tableOptionsPanel.add(rowSelectionCheckBox, "cell 1 1");
|
||||||
|
|
||||||
|
//---- focusCellEditorCheckBox ----
|
||||||
|
focusCellEditorCheckBox.setText("focus cell editor");
|
||||||
|
focusCellEditorCheckBox.addActionListener(e -> focusCellEditorChanged());
|
||||||
|
tableOptionsPanel.add(focusCellEditorCheckBox, "cell 2 1");
|
||||||
|
|
||||||
//---- showVerticalLinesCheckBox ----
|
//---- showVerticalLinesCheckBox ----
|
||||||
showVerticalLinesCheckBox.setText("show vertical lines");
|
showVerticalLinesCheckBox.setText("show vertical lines");
|
||||||
showVerticalLinesCheckBox.addActionListener(e -> showVerticalLinesChanged());
|
showVerticalLinesCheckBox.addActionListener(e -> showVerticalLinesChanged());
|
||||||
@@ -867,7 +879,7 @@ public class FlatComponents2Test
|
|||||||
//---- tableHeaderButtonCheckBox ----
|
//---- tableHeaderButtonCheckBox ----
|
||||||
tableHeaderButtonCheckBox.setText("show button in table header");
|
tableHeaderButtonCheckBox.setText("show button in table header");
|
||||||
tableHeaderButtonCheckBox.addActionListener(e -> tableHeaderButtonChanged());
|
tableHeaderButtonCheckBox.addActionListener(e -> tableHeaderButtonChanged());
|
||||||
tableOptionsPanel.add(tableHeaderButtonCheckBox, "cell 1 4");
|
tableOptionsPanel.add(tableHeaderButtonCheckBox, "cell 1 4 2 1");
|
||||||
}
|
}
|
||||||
add(tableOptionsPanel, "cell 4 4 2 1");
|
add(tableOptionsPanel, "cell 4 4 2 1");
|
||||||
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
||||||
@@ -897,6 +909,7 @@ public class FlatComponents2Test
|
|||||||
private JComboBox<String> sortIconPositionComboBox;
|
private JComboBox<String> sortIconPositionComboBox;
|
||||||
private JCheckBox showHorizontalLinesCheckBox;
|
private JCheckBox showHorizontalLinesCheckBox;
|
||||||
private JCheckBox rowSelectionCheckBox;
|
private JCheckBox rowSelectionCheckBox;
|
||||||
|
private JCheckBox focusCellEditorCheckBox;
|
||||||
private JCheckBox showVerticalLinesCheckBox;
|
private JCheckBox showVerticalLinesCheckBox;
|
||||||
private JCheckBox columnSelectionCheckBox;
|
private JCheckBox columnSelectionCheckBox;
|
||||||
private JCheckBox intercellSpacingCheckBox;
|
private JCheckBox intercellSpacingCheckBox;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
JFDML JFormDesigner: "7.0.4.0.360" Java: "16" encoding: "UTF-8"
|
JFDML JFormDesigner: "7.0.5.0.382" Java: "16" encoding: "UTF-8"
|
||||||
|
|
||||||
new FormModel {
|
new FormModel {
|
||||||
contentType: "form/swing"
|
contentType: "form/swing"
|
||||||
@@ -8,7 +8,7 @@ new FormModel {
|
|||||||
}
|
}
|
||||||
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||||
"$layoutConstraints": "ltr,insets dialog,hidemode 3"
|
"$layoutConstraints": "ltr,insets dialog,hidemode 3"
|
||||||
"$columnConstraints": "[][200,grow,sizegroup 1,fill][200,grow,sizegroup 1,fill][fill][200,grow,sizegroup 1,fill][200,grow,sizegroup 1,fill]"
|
"$columnConstraints": "[][200,grow,sizegroup 1,fill][200,grow,sizegroup 1,fill]para[fill][200,grow,sizegroup 1,fill][200,grow,sizegroup 1,fill]"
|
||||||
"$rowConstraints": "[][150,grow,sizegroup 1,fill][150,grow,sizegroup 1,fill][150,grow,sizegroup 1,fill][fill]"
|
"$rowConstraints": "[][150,grow,sizegroup 1,fill][150,grow,sizegroup 1,fill][150,grow,sizegroup 1,fill][fill]"
|
||||||
} ) {
|
} ) {
|
||||||
name: "this"
|
name: "this"
|
||||||
@@ -372,7 +372,7 @@ 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": "hidemode 3"
|
"$layoutConstraints": "hidemode 3"
|
||||||
"$columnConstraints": "[][fill]"
|
"$columnConstraints": "[][fill][fill]"
|
||||||
"$rowConstraints": "[][]0[]0[]0[]0"
|
"$rowConstraints": "[][]0[]0[]0[]0"
|
||||||
} ) {
|
} ) {
|
||||||
name: "tableOptionsPanel"
|
name: "tableOptionsPanel"
|
||||||
@@ -381,7 +381,7 @@ new FormModel {
|
|||||||
name: "autoResizeModeLabel"
|
name: "autoResizeModeLabel"
|
||||||
"text": "Auto resize mode:"
|
"text": "Auto resize mode:"
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 0 2 1"
|
"value": "cell 0 0 3 1"
|
||||||
} )
|
} )
|
||||||
add( new FormComponent( "javax.swing.JComboBox" ) {
|
add( new FormComponent( "javax.swing.JComboBox" ) {
|
||||||
name: "autoResizeModeField"
|
name: "autoResizeModeField"
|
||||||
@@ -400,13 +400,13 @@ new FormModel {
|
|||||||
}
|
}
|
||||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "autoResizeModeChanged", false ) )
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "autoResizeModeChanged", false ) )
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 0 2 1"
|
"value": "cell 0 0 3 1"
|
||||||
} )
|
} )
|
||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "sortIconPositionLabel"
|
name: "sortIconPositionLabel"
|
||||||
"text": "Sort icon:"
|
"text": "Sort icon:"
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 0 2 1"
|
"value": "cell 0 0 3 1"
|
||||||
} )
|
} )
|
||||||
add( new FormComponent( "javax.swing.JComboBox" ) {
|
add( new FormComponent( "javax.swing.JComboBox" ) {
|
||||||
name: "sortIconPositionComboBox"
|
name: "sortIconPositionComboBox"
|
||||||
@@ -422,7 +422,7 @@ new FormModel {
|
|||||||
}
|
}
|
||||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "sortIconPositionChanged", false ) )
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "sortIconPositionChanged", false ) )
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 0 2 1"
|
"value": "cell 0 0 3 1"
|
||||||
} )
|
} )
|
||||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
name: "showHorizontalLinesCheckBox"
|
name: "showHorizontalLinesCheckBox"
|
||||||
@@ -445,6 +445,16 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 1 1"
|
"value": "cell 1 1"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
|
name: "focusCellEditorCheckBox"
|
||||||
|
"text": "focus cell editor"
|
||||||
|
auxiliary() {
|
||||||
|
"JavaCodeGenerator.variableLocal": false
|
||||||
|
}
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "focusCellEditorChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 2 1"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
name: "showVerticalLinesCheckBox"
|
name: "showVerticalLinesCheckBox"
|
||||||
"text": "show vertical lines"
|
"text": "show vertical lines"
|
||||||
@@ -503,14 +513,14 @@ new FormModel {
|
|||||||
}
|
}
|
||||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "tableHeaderButtonChanged", false ) )
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "tableHeaderButtonChanged", false ) )
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 1 4"
|
"value": "cell 1 4 2 1"
|
||||||
} )
|
} )
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 4 4 2 1"
|
"value": "cell 4 4 2 1"
|
||||||
} )
|
} )
|
||||||
}, 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( 1000, 600 )
|
"size": new java.awt.Dimension( 1095, 610 )
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user