shortcut set for tabs in Jtabbedpane not working properly
hi,
i have problem with Jtabbedpane . In my frame, am having one Jtabbedpane and few releated buttons.
I set shortcut for tabs in jtabbedpane as following,
distanceTabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
distanceTabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
similarly i have shortcuts for other buttons in my frame.
at the begining everything works properly, but whenever a button action event happens shortcut i set for jtabbedpane tabs not working.
All other shortcuts i set for buttons working properly.
I have my own FocusTraversalPolicy too.
am thankful if anyone give solution or suggestion for my problem.
regards
bala
[703 byte] By [
bala.ibsa] at [2007-11-26 18:03:25]

# 1
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.
# 2
hi,
thank a lot for your response.
here i attached sample code of my problem
JTabbedpane has Mnemonic Alt+1 & Alt+2
but its not working when application starts.
after JTabbedpane getting focus through mouse or keyboard only these mnemonic works
Even after if focus goes to save button or close button, these mnemonic are not working.
just run this sample code, u can understand my problem.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class test extends JFrame {
public test() {
JPanel panel1 = new JPanel();
JButton b1 = new JButton( "save" );
b1.setMnemonic('s');JButton b2 = new JButton( "close" );
b2.setMnemonic('c');
panel1.add( b1 );
panel1.add( b2 );
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
panel2.add(new JTextField("First"));
panel3.add(new JTextField("Second"));
JTabbedPane tab = new JTabbedPane();
tab.add(panel2);
tab.add(panel3);
tab.setTitleAt(0,"First");
tab.setMnemonicAt(0, KeyEvent.VK_1);tab.setTitleAt(1,"Second");
tab.setMnemonicAt(1, KeyEvent.VK_2);
getContentPane().add( panel1, BorderLayout.NORTH );
getContentPane().add( tab, BorderLayout.CENTER );
setSize(400,400);
setVisible( true );
}
/**
* @param args
*/
public static void main( String[] args ) {
test t = new test();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
# 3
No formatted code, no help!
# 4
is this ok............
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class test extends JFrame {
public test() {
JPanel panel1 = new JPanel();
JButton b1 = new JButton( "save" );
b1.setMnemonic('s');
JButton b2 = new JButton( "close" );
b2.setMnemonic('c');
panel1.add( b1 );
panel1.add( b2 );
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
panel2.add(new JTextField("First"));
panel3.add(new JTextField("Second"));
JTabbedPane tab = new JTabbedPane();
tab.add(panel2);
tab.add(panel3);
tab.setTitleAt(0,"First");
[b]tab.setMnemonicAt(0, KeyEvent.VK_1);[/b]
tab.setTitleAt(1,"Second");
[b]tab.setMnemonicAt(1, KeyEvent.VK_2);[/b]
getContentPane().add( panel1, BorderLayout.NORTH );
getContentPane().add( tab, BorderLayout.CENTER );
setSize(400,400);
setVisible( true );
}
/**
* @param args
*/
public static void main( String[] args ) {
test t = new test();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}