Skip to content

Commit

Permalink
fixed actionlistener issue with jtextfield
Browse files Browse the repository at this point in the history
  • Loading branch information
atarw committed Jul 27, 2018
1 parent 5943931 commit 1751add
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 53 deletions.
81 changes: 35 additions & 46 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified lib/material-ui-swing.jar
Binary file not shown.
21 changes: 14 additions & 7 deletions src/mdlaf/components/textfield/MaterialTextFieldUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,8 @@ public void installUI (JComponent c) {

JTextField textField = (JTextField) c;
textField.setOpaque (false);

if (drawLine) {
textField.setBorder (BorderFactory.createEmptyBorder (5, 2, 10, 0));
}
else {
textField.setBorder (BorderFactory.createEmptyBorder (2, 2, 2, 2));
}
textField.setBorder (drawLine ? BorderFactory.createEmptyBorder (5, 2, 10, 0) :
BorderFactory.createEmptyBorder (2, 2, 2, 2));

textField.setBackground (MaterialColors.LIGHT_BLUE_400);
textField.setFont (MaterialFonts.REGULAR);
Expand All @@ -60,6 +55,7 @@ public void installUI (JComponent c) {

@Override
protected void installListeners () {
super.installListeners ();
getComponent ().addFocusListener (this);
getComponent ().addPropertyChangeListener (this);
}
Expand Down Expand Up @@ -106,16 +102,25 @@ public void actionPerformed (ActionEvent e) {
}
};

Action enter = new AbstractAction () {
@Override
public void actionPerformed (ActionEvent e) {
((JTextField) getComponent ()).postActionEvent ();
}
};

// note getMenuShortcutKeyMask() is deprecated in Java 10 - change to getMenuShortcutKeyMaskEx()
getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_A, Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask ()), "selectAll");
getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_BACK_SPACE, 0), "delete");
getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_LEFT, 0), "left");
getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_RIGHT, 0), "right");
getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_ENTER, 0), "enter");

getComponent ().getActionMap ().put ("selectAll", selectAll);
getComponent ().getActionMap ().put ("delete", delete);
getComponent ().getActionMap ().put ("left", left);
getComponent ().getActionMap ().put ("right", right);
getComponent ().getActionMap ().put ("enter", enter);
}

@Override
Expand Down Expand Up @@ -165,6 +170,8 @@ public void focusLost (FocusEvent e) {

@Override
public void propertyChange (PropertyChangeEvent pce) {
super.propertyChange (pce);

if (pce.getPropertyName ().equals ("background")) {
Color newColor = (Color) pce.getNewValue ();

Expand Down

0 comments on commit 1751add

Please sign in to comment.