Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Enabling the Selection of a Tab in a JTabbedPane Container Using a Keystroke

import java.awt.event.KeyEvent; import javax.swing.JButton; import javax.swing.JTabbedPane; public class Main {   public static void main(String[] argv) throws Exception {     JTabbedPane pane = new JTabbedPane();     pane.addTab("Tab Label", new JButton("button"));     int index = pane.getTabCount() - 1;     int keycode = KeyEvent.VK_L;     pane.setMnemonicAt(index, keycode);   } }