Top most string field gets focus if the attribute dialog is opened

This commit is contained in:
hneemann 2017-05-27 23:10:32 +02:00
parent 5c010f8396
commit c9b65df256
2 changed files with 11 additions and 1 deletions

View File

@ -31,6 +31,7 @@ public class AttributeDialog extends JDialog {
private final Point pos;
private final ElementAttributes elementAttributes;
private final JPanel buttonPanel;
private JComponent topMostTextComponent;
private VisualElement visualElement;
private boolean changed = false;
@ -66,8 +67,11 @@ public class AttributeDialog extends JDialog {
editors = new ArrayList<>();
topMostTextComponent = null;
for (Key key : list) {
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));
e.addToPanel(panel, key, elementAttributes, this);
}
@ -154,6 +158,9 @@ public class AttributeDialog extends JDialog {
else
setLocation(pos.x, pos.y);
if (topMostTextComponent != null)
SwingUtilities.invokeLater(() -> topMostTextComponent.requestFocusInWindow());
setVisible(true);
return changed;
}

View File

@ -128,7 +128,7 @@ public final class EditorFactory {
//Checkstyle flags redundant modifiers, which are not redundant. Maybe a bug in checkstyle?
//CHECKSTYLE.OFF: RedundantModifier
private final static class StringEditor extends LabelEditor<String> {
final static class StringEditor extends LabelEditor<String> {
private final JTextComponent text;
private final JComponent compToAdd;
@ -155,6 +155,9 @@ public final class EditorFactory {
return text.getText().trim();
}
public JTextComponent getTextComponent() {
return text;
}
}
private final static class IntegerEditor extends LabelEditor<Integer> {