mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-28 15:32:40 -04:00
Top most string field gets focus if the attribute dialog is opened
This commit is contained in:
parent
5c010f8396
commit
c9b65df256
@ -31,6 +31,7 @@ public class AttributeDialog extends JDialog {
|
|||||||
private final Point pos;
|
private final Point pos;
|
||||||
private final ElementAttributes elementAttributes;
|
private final ElementAttributes elementAttributes;
|
||||||
private final JPanel buttonPanel;
|
private final JPanel buttonPanel;
|
||||||
|
private JComponent topMostTextComponent;
|
||||||
private VisualElement visualElement;
|
private VisualElement visualElement;
|
||||||
private boolean changed = false;
|
private boolean changed = false;
|
||||||
|
|
||||||
@ -66,8 +67,11 @@ public class AttributeDialog extends JDialog {
|
|||||||
|
|
||||||
editors = new ArrayList<>();
|
editors = new ArrayList<>();
|
||||||
|
|
||||||
|
topMostTextComponent = null;
|
||||||
for (Key key : list) {
|
for (Key key : list) {
|
||||||
Editor e = EditorFactory.INSTANCE.create(key, elementAttributes.get(key));
|
Editor e = EditorFactory.INSTANCE.create(key, elementAttributes.get(key));
|
||||||
|
if (topMostTextComponent == null && e instanceof EditorFactory.StringEditor)
|
||||||
|
topMostTextComponent = ((EditorFactory.StringEditor) e).getTextComponent();
|
||||||
editors.add(new EditorHolder(e, key));
|
editors.add(new EditorHolder(e, key));
|
||||||
e.addToPanel(panel, key, elementAttributes, this);
|
e.addToPanel(panel, key, elementAttributes, this);
|
||||||
}
|
}
|
||||||
@ -154,6 +158,9 @@ public class AttributeDialog extends JDialog {
|
|||||||
else
|
else
|
||||||
setLocation(pos.x, pos.y);
|
setLocation(pos.x, pos.y);
|
||||||
|
|
||||||
|
if (topMostTextComponent != null)
|
||||||
|
SwingUtilities.invokeLater(() -> topMostTextComponent.requestFocusInWindow());
|
||||||
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ public final class EditorFactory {
|
|||||||
|
|
||||||
//Checkstyle flags redundant modifiers, which are not redundant. Maybe a bug in checkstyle?
|
//Checkstyle flags redundant modifiers, which are not redundant. Maybe a bug in checkstyle?
|
||||||
//CHECKSTYLE.OFF: RedundantModifier
|
//CHECKSTYLE.OFF: RedundantModifier
|
||||||
private final static class StringEditor extends LabelEditor<String> {
|
final static class StringEditor extends LabelEditor<String> {
|
||||||
|
|
||||||
private final JTextComponent text;
|
private final JTextComponent text;
|
||||||
private final JComponent compToAdd;
|
private final JComponent compToAdd;
|
||||||
@ -155,6 +155,9 @@ public final class EditorFactory {
|
|||||||
return text.getText().trim();
|
return text.getText().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JTextComponent getTextComponent() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static class IntegerEditor extends LabelEditor<Integer> {
|
private final static class IntegerEditor extends LabelEditor<Integer> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user