Hallo zusammen!
Ich verwende eine InputMap, damit mein Button auch bei ENTER reagiert und die Aktionen, die im ActionListener definiert sind, ausgeführt werden. Leider verlangt aber der Button beim Setzen der InputMap einen Int-Wert. Die Vorgaben gemäss der API funktionieren nicht...
Bei ... müsste man eine der folgenden Values definieren können, nur eben gibts die irgendwie gar nicht, er nimmt sie nicht an.
Die API zu dieser Klasse:
Ich verwende eine InputMap, damit mein Button auch bei ENTER reagiert und die Aktionen, die im ActionListener definiert sind, ausgeführt werden. Leider verlangt aber der Button beim Setzen der InputMap einen Int-Wert. Die Vorgaben gemäss der API funktionieren nicht...
Java:
InputMap b_search_map = new InputMap();
KeyStroke enterReleased = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true);
// Konfiguration des Such-Buttons
b_search.addActionListener(this);
b_search.setPreferredSize(new Dimension(150, COMP_HEIGHT));
b_search.setFont(new Font("Arial", Font.BOLD, 12));
b_search.setForeground(Color.RED);
b_search.setInputMap(... , b_search_map);
// Der InputMap (für ENTER-Tasten Reaktion) den Such-Button zuweisen
b_search_map = b_search.getInputMap();
b_search_map.put(enterReleased,"released");
Bei ... müsste man eine der folgenden Values definieren können, nur eben gibts die irgendwie gar nicht, er nimmt sie nicht an.
Die API zu dieser Klasse:
javax.swing.JComponent
public final void setInputMap(int i, InputMap im)
Sets the InputMap to use under the condition condition to map. A null value implies you do not want any bindings to be used, even from the UI. This will not reinstall the UI InputMap (if there was one). condition has one of the following values:
> WHEN_IN_FOCUSED_WINDOW
> WHEN_FOCUSED
> WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
If condition is WHEN_IN_FOCUSED_WINDOW and map is not a ComponentInputMap, an IllegalArgumentException will be thrown. Similarly, if condition is not one of the values listed, an IllegalArgumentException will be thrown.
Parameters:
condition - one of the values listed above
map - the InputMap to use for the given condition
Throws:
IllegalArgumentException - if condition is WHEN_IN_FOCUSED_WINDOW and map is not an instance of ComponentInputMap; or if condition is not one of the legal values specified above
Since: 1.3