Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #3838 > unrolled thread

JTabbedPane with Keyevent

Started bypinik.smily4u@gmail.com.remove-dii-this
First post2011-04-27 15:47 +0000
Last post2011-04-27 15:47 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.gui


Contents

  JTabbedPane with Keyevent pinik.smily4u@gmail.com.remove-dii-this - 2011-04-27 15:47 +0000
    Re: JTabbedPane with Keye "John B. Matthews" <john.b..matthews@THRWHITE.remove-dii-this> - 2011-04-27 15:47 +0000

#3838 — JTabbedPane with Keyevent

Frompinik.smily4u@gmail.com.remove-dii-this
Date2011-04-27 15:47 +0000
SubjectJTabbedPane with Keyevent
Message-ID<36d87bb1-1187-444e-b040-fe5add1e7538@x41g2000hsb.googlegroups.com>
  To: comp.lang.java.gui
I have created a tabbedpane with 3 tabs (Tab1, Tab2, Tab3) . Mnemonic
(ALT-F) is assigned only to the Tab1.

If any of the component is selected inside the Tab2 or Tab3, it can
still traverse back to Tab1 on pressing key ALT-F.
But if any component is selected in the Tab1 itself, pressing ALT-F
will not take me back to Tab1. I have to somehow get the focus for
Tab1 too.


Here is  my code. Please respond to this.
Thank you.


Note:  I don’t  want to set Mnemonic to each Tab. Only one Mnemonic
should do my work.


import java.awt.BorderLayout;
import java.awt.event.KeyEvent;


import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


public class myClass {


        public static void main(String args[]) throws Exception {


            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


             JTabbedPane tabbedPane = new JTabbedPane();


            JButton button1= new JButton("Button1");
            JButton button2= new JButton("Button2");
            JPanel panel1 = new JPanel();
            panel1.add(button1);
            panel1.add(button2);


            tabbedPane.addTab("Tab1", null, panel1, null);


            JLabel label = new JLabel("Check ");
            JCheckBox cbox = new JCheckBox("check me");
            JPanel panel = new JPanel();
            panel.add(label, null);
            panel.add(cbox);


            tabbedPane.addTab("Tab2", null, panel, null);


            JButton button2 = new JButton("Button");
            tabbedPane.addTab("Tab3", null, button2, null);


             int mnemonic = KeyEvent.VK_F;


tabbedPane.setMnemonicAt(tabbedPane.getSelectedIndex(), mnemonic);


            ChangeListener changeListener = new ChangeListener() {
                public void stateChanged(ChangeEvent changeEvent) {


                    JTabbedPane tab =
(JTabbedPane)changeEvent.getSource();
                    int index = tab.getSelectedIndex();


                    if(index==0)
                   tab.requestFocus();


                  }
              };
              tabbedPane.addChangeListener(changeListener);


            frame.add(tabbedPane, BorderLayout.CENTER);
            frame.setSize(400, 150);
            frame.setVisible(true);


        }

}

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#3841 — Re: JTabbedPane with Keye

From"John B. Matthews" <john.b..matthews@THRWHITE.remove-dii-this>
Date2011-04-27 15:47 +0000
SubjectRe: JTabbedPane with Keye
Message-ID<nospam-FB270A.13545529072008@aioe.org>
In reply to#3838
  To: comp.lang.java.gui
In article 
<36d87bb1-1187-444e-b040-fe5add1e7538@x41g2000hsb.googlegroups.com>,
 "pinik.smily4u@gmail.com" <pinik.smily4u@gmail.com> wrote:

> I have created a tabbedpane with 3 tabs (Tab1, Tab2, Tab3) . Mnemonic 
> (ALT-F) is assigned only to the Tab1.
> 
> If any of the component is selected inside the Tab2 or Tab3, it can 
> still traverse back to Tab1 on pressing key ALT-F. But if any 
> component is selected in the Tab1 itself, pressing ALT-F will not 
> take me back to Tab1. I have to somehow get the focus for Tab1 too.

Do the other two methods for tab navigation (mouse or keyboard arrows) 
work?

<http://java.sun.com/docs/books/tutorial/uiswing/components/tabbedpane.ht
ml>

[...]
> Note:  I don|t  want to set Mnemonic to each Tab. Only one Mnemonic
> should do my work.
[...]
>             JButton button2= new JButton("Button2");
[...]
>             JButton button2 = new JButton("Button");
>             tabbedPane.addTab("Tab3", null, button2, null);

Should this be button3?

-- 
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web