I have a section in my GUI that is generated dynamically according to a list of objects. So, for each object in that list I want to create a JButton and associate a keyboard shortcut.
For example:
for (String tag : testTags) {
new JButton(tag).setMnemonic(KeyEvent.VK_F1);
}
How do I make the code "setMnemonic(KeyEvent.VK_F1)" dynamic in an elegant way? Is there some way to get a range of keys automatically and then use it in this iteration?
Thanks!
An Action
is well suited for this. See How to Use Actions for more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With