JTabbedPane and focus problem.

Hello. I currently have a JTabbedPane which contains the various panels that make up different tabs. These tabs are extensions of panels, and are seperate classes imported into the class which contains my JTabbedPane and then added. The frame which conatins my JTabbedPane also has a button, which when pressed I wish it to look at the tab which is currently active, and call a method from the class which this tab refers to. The problem is that I don't know how to get my button to determine which tab is currently active. Any help will be gratefully recieved.

Use getSelectedComponent() or getSelectedIndex() of your JTabbedPane object.

Similar Messages

  • JTabbedPane and JScrollPane problem

    Hi all,
    I'm trying to make working JScrollPane into JTabbedPane. I have been trying several times to make it but with no acceptable effects :( I attached below the simple code to show what I'm interested in.
    PANEL1 has its dimension. I'd like to make that the JScrollPane will be active and enabled to roll when user change JFrame size to less than PANEL1 on pane1.
    Please help!
    Thanks for everyone,
    Greetings,
    import java.lang.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class Sample     {
    static JFrame fr;
    static JPanel pane1, pane2, pane3;
    static JLabel AAA, BBB, CCC;
    static JPanel PANEL1;
    static JTabbedPane panel;
    public static void main(String args[])     {
              fr = new JFrame("Sample");
              pane1 = new JPanel();
              pane1.setLayout(null);
              pane2 = new JPanel();
              pane2.setLayout(null);
              pane3 = new JPanel();
              pane3.setLayout(null);
              panel = new JTabbedPane();
              Font myfont1 = new Font("SansSerif",0,20);
              Font myfont2 = new Font("SansSerif",0,15);
              Font myfont3 = new Font("SensSerif",1,15);
              AAA = new JLabel("AAA");
              BBB = new JLabel("BBB");
              CCC = new JLabel("CCC");
              AAA.setFont(myfont2);
              BBB.setFont(myfont2);
              CCC.setFont(myfont2);
              AAA.setBounds(20,20,300,20);
              BBB.setBounds(20,50,300,20);
              CCC.setBounds(20,80,300,20);
              PANEL1 = new JPanel();
              PANEL1.setLayout(null);
              PANEL1.setBackground(java.awt.Color.CYAN);
              PANEL1.setBounds(20,15,250,300);
              PANEL1.add(AAA);
              PANEL1.add(BBB);
              PANEL1.add(CCC);
              pane1.add(PANEL1);
              panel.insertTab("A", null, pane1, null, 0);
              panel.setSelectedIndex(0);
              panel.insertTab("B", null, pane2, null, 1);
              panel.setSelectedIndex(0);
              panel.insertTab("C", null, pane3, null, 2);
              panel.setSelectedIndex(0);
              panel.setBounds(0,0,550,450);
              fr.setLayout(null);
              //fr.setResizable(false);
              fr.setBackground(java.awt.Color.CYAN);
              fr.setForeground(java.awt.Color.CYAN);
              fr.add(panel);
              fr.pack();
              fr.setSize(550, 450);
              fr.setLocationRelativeTo(null);
              fr.setVisible(true);
    }

    Unfortunately no :( Besides, I can't understand at
    all this line:
    JTabbedPane (panel)TabbedPane = ... new
    w JTabbedPane(...).add/insertTab( ... new
    JScrollPane(new JPanel(...)) ... )It's to big cut-off like for me. Can you insert it
    into my Sample?
    Regards and thanks,It's only my "dev speak". Put a ";" and a var name (, ...) whereever needed, and remove some"()".
    (Sorry, normally I don't help dev beginners on so more complex problems, with just an easy answer.)

  • JTabbedPane and focus

    I use a jTabbedPane in order to make un chain progression in data collections.
    I've searched in the functions and variables to know if it is possible to block
    the user on the last TabbedPane if he start using the last TabbedPane.
    I've placed previous and next buttons on each TabbedPane and i can disable these buttons,
    but i can't disable the tabbedPane above.
    I don't wish to use CardLayout for this (event if it is better for that), so if someone know how to
    solve this problem, thanks in advance.

    You can use JTabbedPane.setEnabledAt to set whether a particular tab is enabled or not. Just make a call to this with the code that enables/disables your previous and next buttons.
    Hope this helps.

  • Switch contentpane AND focus problem

    Hi,
    I would like to switch contentpane when user click on a JButton. I do something like this :
    void clientButton_actionPerformed(ActionEvent e) {
    GestionClient gc = new GestionClient(this);
    gc.pack();
    this.setContentPane(gc.contentPane);
    this.getContentPane().setSize(this.getSize());
    this.validate();
    where GestionClient is another JFrame containing the new contentpane.
    Well it works but I would like to know if it is the right way to do this ?
    But in my contentPane, I can't get a JTextField to be the focused item ! I've tried jTextField1.requestFocus() and jTextField1.grabFocus() but it doesn't work, the focusOwner still is the menu's button clicked.
    Any idea ?
    Thanx
    -NicO-

    Well it works but I would like to know if it is the
    right way to do this ?I dont really like it.
    Why not:
    JPanel panel = new JPanel();
    panel.add(...); // create/add the components
    setContentPane(panel);
    panel.validate();Seems cleaner.
    But in my contentPane, I can't get a JTextField to be
    the focused item ! I've tried
    jTextField1.requestFocus() and jTextField1.grabFocus()
    but it doesn't work, the focusOwner still is the
    menu's button clicked.This can have many causes :-( The most probable are:
    1. The texfield is not yet visible when you request focus to it (invisible components ignore focus requests).
    2. There are pending swing events that change the focus.
    I usually do the request focus using SwingUtilities.invokeLater().
    This helps ensure the event queue is cleaner.

  • JTabbedPane loosing focus when switching tabs

    When there are tiered JTabbedPanes and focus in one of the children and the tabbed is switched focus will go to the first component in the frame.
    Is there a work around to keep the focus at least on the jtabbedpane?
    Is this a know bug? anyone heard of this before?
    Googling: JTabbedPane focus didn't bring up anything helpful... is there something else I should be searching under?
    Here is an example:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    public class TabPaneTest extends JFrame {
        public TabPaneTest() {
            JButton focusStealer = new JButton("Look at me!");
            focusStealer.addFocusListener(new FocusListener() {
                public void focusGained(FocusEvent e) {
                    System.out.println("I TOOK FOCUS! W00t!");
                public void focusLost(FocusEvent e) {
                    //To change body of implemented methods use File | Settings | File Templates.
            JTabbedPane tabbedPane = createTabbedPane(0);
            getContentPane().add(focusStealer, BorderLayout.NORTH);
            getContentPane().add(tabbedPane, BorderLayout.CENTER);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(300, 200);
            setLocation(400, 200);
            setVisible(true);
        private JTabbedPane createTabbedPane(int deep) {
            deep++;
            JTabbedPane tabs = new JTabbedPane();
            for (int i = 0; i < 4; i++) {
                if (deep < 4) {
                    tabs.add(i + ":" + deep + " - Focus", createTabbedPane(deep));
                } else {
                    tabs.add(i + ":" + deep + " - Focus", new JTextField());
            return tabs;
        public static void main(String[] args) {
            new TabPaneTest();
    }

    When there are tiered JTabbedPanes and focus in one of the children and the tabbed is switched focus will go to the first component in the frame.
    Is there a work around to keep the focus at least on the jtabbedpane?
    Is this a know bug? anyone heard of this before?
    Googling: JTabbedPane focus didn't bring up anything helpful... is there something else I should be searching under?
    Here is an example:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    public class TabPaneTest extends JFrame {
        public TabPaneTest() {
            JButton focusStealer = new JButton("Look at me!");
            focusStealer.addFocusListener(new FocusListener() {
                public void focusGained(FocusEvent e) {
                    System.out.println("I TOOK FOCUS! W00t!");
                public void focusLost(FocusEvent e) {
                    //To change body of implemented methods use File | Settings | File Templates.
            JTabbedPane tabbedPane = createTabbedPane(0);
            getContentPane().add(focusStealer, BorderLayout.NORTH);
            getContentPane().add(tabbedPane, BorderLayout.CENTER);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(300, 200);
            setLocation(400, 200);
            setVisible(true);
        private JTabbedPane createTabbedPane(int deep) {
            deep++;
            JTabbedPane tabs = new JTabbedPane();
            for (int i = 0; i < 4; i++) {
                if (deep < 4) {
                    tabs.add(i + ":" + deep + " - Focus", createTabbedPane(deep));
                } else {
                    tabs.add(i + ":" + deep + " - Focus", new JTextField());
            return tabs;
        public static void main(String[] args) {
            new TabPaneTest();
    }

  • Problem while adding both Key And Focus Listeners to JTextField

    Hi!
    I have something peculiar while adding Key and Focus Listener to JTextField. Suppose i add just Key Listener then everything's fine and i could keep track of keys being pressed. But as soon as i add a Focus Listener to it with the code to select full text in focusGained() method, it starts reponding wrongly to arrow keys pressed and does not perform desired actions. For let arrow key it moves caret by one for the first time after that it does not resond to that unless caret is changed by using mouse. If right arrow key is pressed the it moves the caret to last position from wherever it is. For UP and DOWN it selects the full text(This should be done when it gets focus)
    public void focusGained(FocusEvent fe)
    setCaretPosition(0);
    moveCaretPosition(getDocument().getLength());
    Can someone help me out on this?
    thanks and regards,
    Amit.

    None of those things will cause your JFrame to resize itself. And this is probably a good thing, because your JFrame shouldn't change size once you have created it. Why not create your JPanel so that it has enough space for you to add the component later? Or why not just add the component to start with and then enable it or make it editable when you decide that's necessary?

  • Focus Problem on Solaris with jdk 1.3.1

    Hi all,
    We are having a focus problem on Solaris. The same code works fine on Windows without any problem.
    I am sending the test code and run steps below which you can compile and repeat the problem.
    NOTE: When we put a comment on the line "f1.requestFocus();" in TestFocus.java it works OK.
    Run Steps :
    1. Run TestFocus.class
    2. A JFrame appears with 2 text field and a button
    3. Try to write something on the text fields. It works OK.
    4. Click the button to open a new JFrame
    5. A new JFrame opens with a single text field and a button.
    6. Click the button to close the second frame
    7. You are now on the main JFrame
    8. Try to write something on the text fields. It works OK.
    9. Repeat the steps 4-7
    10. Try to write something on the text fields. You are able to focus and write on the first field. BUT you cannot select or write the second Field!
    JAVA SOURCE FILES :
    PenHesapListener.java :
    public interface PenHesapListener extends java.util.EventListener {
    void tamam_actionPerformed(java.util.EventObject newEvent);
    void iptal_actionPerformed(java.util.EventObject newEvent);
    ------PenHesapLisEventMulticaster.java----------------------------------
    public class PenHesapLisEventMulticaster extends java.awt.AWTEventMulticaster implements PenHesapListener {
    * Constructor to support multicast events.
    * @param a java.util.EventListener
    * @param b java.util.EventListener
    protected PenHesapLisEventMulticaster(java.util.EventListener a, java.util.EventListener b) {
         super(a, b);
    * Add new listener to support multicast events.
    * @return muhasebe.HesappenListener
    * @param a muhasebe.HesappenListener
    * @param b muhasebe.HesappenListener
    public static PenHesapListener add(PenHesapListener a, PenHesapListener b) {
         return (PenHesapListener)addInternal(a, b);
    * Add new listener to support multicast events.
    * @return java.util.EventListener
    * @param a java.util.EventListener
    * @param b java.util.EventListener
    protected static java.util.EventListener addInternal(java.util.EventListener a, java.util.EventListener b) {
         if (a == null) return b;
         if (b == null) return a;
         return new PenHesapLisEventMulticaster(a, b);
    * @return java.util.EventListener
    * @param oldl muhasebe.HesappenListener
    protected java.util.EventListener remove(PenHesapListener oldl) {
         if (oldl == a) return b;
         if (oldl == b) return a;
         java.util.EventListener a2 = removeInternal(a, oldl);
         java.util.EventListener b2 = removeInternal(b, oldl);
         if (a2 == a && b2 == b)
              return this;
         return addInternal(a2, b2);
    * Remove listener to support multicast events.
    * @return muhasebe.HesappenListener
    * @param l muhasebe.HesappenListener
    * @param oldl muhasebe.HesappenListener
    public static PenHesapListener remove(PenHesapListener l, PenHesapListener oldl) {
         if (l == oldl || l == null)
              return null;
         if(l instanceof PenHesapLisEventMulticaster)
              return (PenHesapListener)((PenHesapLisEventMulticaster) l).remove(oldl);
         return l;
    public void tamam_actionPerformed(java.util.EventObject newEvent) {
         ((PenHesapListener)a).tamam_actionPerformed(newEvent);
         ((PenHesapListener)b).tamam_actionPerformed(newEvent);
    public void iptal_actionPerformed(java.util.EventObject newEvent) {
         ((PenHesapListener)a).iptal_actionPerformed(newEvent);
         ((PenHesapListener)b).iptal_actionPerformed(newEvent);
    ---------TestFocus2.java-----------------------------------------
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import java.awt.event.WindowAdapter;
    import java.awt.event.KeyListener;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.StringTokenizer;
    import java.text.SimpleDateFormat;
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.Color;
    import java.util.Locale;
    import java.util.ResourceBundle;
    public class TestFocus2 extends JFrame implements ActionListener
         protected transient PenHesapListener PenhListener = null ;
         JTextField f10 = null;
         JButton b10= null ;
         JTextField f1 = new JTextField() ;
         JButton b1 = new JButton() ;
         JFrame f20 = null;
         public TestFocus2()
              getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
              getContentPane().add(f1);
              getContentPane().add(b1);
              pack();
              setVisible(true);
              b1.addActionListener(this);
         public void actionPerformed(ActionEvent e)
              if(e.getSource() == b1)
                   fireTamam_actionPerformed(e);
         public void addPenHesapListener(PenHesapListener newListener)
              PenhListener = PenHesapLisEventMulticaster.add(PenhListener, newListener);
              return;
         protected void fireTamam_actionPerformed(java.util.EventObject newEvent) {
              PenhListener.tamam_actionPerformed(newEvent);
              this.setVisible(false);
         protected void fireiptal_actionPerformed(java.util.EventObject newEvent) {
              PenhListener.iptal_actionPerformed(newEvent);
         public static void main(String x[])
              TestFocus2 gen01 = new TestFocus2();
    --------TestFocus.java-----------------------------------
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import java.awt.event.WindowAdapter;
    import java.awt.event.KeyListener;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.StringTokenizer;
    import java.text.SimpleDateFormat;
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.Color;
    import java.util.Locale;
    import java.util.ResourceBundle;
    import java.awt.Container;
    public class TestFocus extends JFrame implements ActionListener
         PenKreKart aPenKreKart = null ;      
         Container ctn = null;
         JTextField f10 = null;
         JButton b10= null ;
         JTextField f1 = new JTextField() ;
         JTextField f2 = new JTextField() ;
         JButton b1 = new JButton() ;
         JFrame f20 = null;
         public TestFocus()
              //aPenKreKart = new PenKreKart(true);
              //aPenKreKart.aTemelPencere.setVisible(false);
              getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
              getContentPane().add(f1);
              getContentPane().add(f2);
              getContentPane().add(b1);
              pack();
              setVisible(true);
              b1.addActionListener(this);
         public void actionPerformed(ActionEvent e)
              if(e.getSource() == b1)
                   pencere_islemi();
         // pencere koyma k?sm? .. begin                               
         public void pencere_islemi() {     
              ctn = this;
              ctn.setEnabled(false);
              TestFocus2 fpen = new TestFocus2();
              //aPenKreKart.aTemelPencere.setVisible(true); //buras?          
              //aPenKreKart.aTemelPencere.addPenHesapListener(new PenHesapListener() {
              fpen.addPenHesapListener(new PenHesapListener() {
                        // metod      tamam_actionPerformed begin...          
                        public void tamam_actionPerformed(java.util.EventObject newEvent) {
                             ctn.setEnabled(true);
                             ctn.requestFocus();
                             // Problem is when we comment the below line it works .....
                             f1.requestFocus();
                             System.out.println("tamam");
                        // metod      tamam_actionPerformed end...          
                        // metod      iptal_actionPerformed begin...          
                        public void iptal_actionPerformed(java.util.EventObject newEvent) {
                             ctn.setEnabled(true);
                             ctn.requestFocus();
                             System.out.println("iptal");
                        // metod      iptal_actionPerformed begin...          
         // pencere koyma k?sm? .. end                               
         public static void main(String x[])
              TestFocus gen01 = new TestFocus();

    Hi all,
    We are having a focus problem on Solaris. The same code works fine on Windows without any problem.
    I am sending the test code and run steps below which you can compile and repeat the problem.
    NOTE: When we put a comment on the line "f1.requestFocus();" in TestFocus.java it works OK.
    Run Steps :
    1. Run TestFocus.class
    2. A JFrame appears with 2 text field and a button
    3. Try to write something on the text fields. It works OK.
    4. Click the button to open a new JFrame
    5. A new JFrame opens with a single text field and a button.
    6. Click the button to close the second frame
    7. You are now on the main JFrame
    8. Try to write something on the text fields. It works OK.
    9. Repeat the steps 4-7
    10. Try to write something on the text fields. You are able to focus and write on the first field. BUT you cannot select or write the second Field!
    JAVA SOURCE FILES :
    PenHesapListener.java :
    public interface PenHesapListener extends java.util.EventListener {
    void tamam_actionPerformed(java.util.EventObject newEvent);
    void iptal_actionPerformed(java.util.EventObject newEvent);
    ------PenHesapLisEventMulticaster.java----------------------------------
    public class PenHesapLisEventMulticaster extends java.awt.AWTEventMulticaster implements PenHesapListener {
    * Constructor to support multicast events.
    * @param a java.util.EventListener
    * @param b java.util.EventListener
    protected PenHesapLisEventMulticaster(java.util.EventListener a, java.util.EventListener b) {
         super(a, b);
    * Add new listener to support multicast events.
    * @return muhasebe.HesappenListener
    * @param a muhasebe.HesappenListener
    * @param b muhasebe.HesappenListener
    public static PenHesapListener add(PenHesapListener a, PenHesapListener b) {
         return (PenHesapListener)addInternal(a, b);
    * Add new listener to support multicast events.
    * @return java.util.EventListener
    * @param a java.util.EventListener
    * @param b java.util.EventListener
    protected static java.util.EventListener addInternal(java.util.EventListener a, java.util.EventListener b) {
         if (a == null) return b;
         if (b == null) return a;
         return new PenHesapLisEventMulticaster(a, b);
    * @return java.util.EventListener
    * @param oldl muhasebe.HesappenListener
    protected java.util.EventListener remove(PenHesapListener oldl) {
         if (oldl == a) return b;
         if (oldl == b) return a;
         java.util.EventListener a2 = removeInternal(a, oldl);
         java.util.EventListener b2 = removeInternal(b, oldl);
         if (a2 == a && b2 == b)
              return this;
         return addInternal(a2, b2);
    * Remove listener to support multicast events.
    * @return muhasebe.HesappenListener
    * @param l muhasebe.HesappenListener
    * @param oldl muhasebe.HesappenListener
    public static PenHesapListener remove(PenHesapListener l, PenHesapListener oldl) {
         if (l == oldl || l == null)
              return null;
         if(l instanceof PenHesapLisEventMulticaster)
              return (PenHesapListener)((PenHesapLisEventMulticaster) l).remove(oldl);
         return l;
    public void tamam_actionPerformed(java.util.EventObject newEvent) {
         ((PenHesapListener)a).tamam_actionPerformed(newEvent);
         ((PenHesapListener)b).tamam_actionPerformed(newEvent);
    public void iptal_actionPerformed(java.util.EventObject newEvent) {
         ((PenHesapListener)a).iptal_actionPerformed(newEvent);
         ((PenHesapListener)b).iptal_actionPerformed(newEvent);
    ---------TestFocus2.java-----------------------------------------
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import java.awt.event.WindowAdapter;
    import java.awt.event.KeyListener;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.StringTokenizer;
    import java.text.SimpleDateFormat;
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.Color;
    import java.util.Locale;
    import java.util.ResourceBundle;
    public class TestFocus2 extends JFrame implements ActionListener
         protected transient PenHesapListener PenhListener = null ;
         JTextField f10 = null;
         JButton b10= null ;
         JTextField f1 = new JTextField() ;
         JButton b1 = new JButton() ;
         JFrame f20 = null;
         public TestFocus2()
              getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
              getContentPane().add(f1);
              getContentPane().add(b1);
              pack();
              setVisible(true);
              b1.addActionListener(this);
         public void actionPerformed(ActionEvent e)
              if(e.getSource() == b1)
                   fireTamam_actionPerformed(e);
         public void addPenHesapListener(PenHesapListener newListener)
              PenhListener = PenHesapLisEventMulticaster.add(PenhListener, newListener);
              return;
         protected void fireTamam_actionPerformed(java.util.EventObject newEvent) {
              PenhListener.tamam_actionPerformed(newEvent);
              this.setVisible(false);
         protected void fireiptal_actionPerformed(java.util.EventObject newEvent) {
              PenhListener.iptal_actionPerformed(newEvent);
         public static void main(String x[])
              TestFocus2 gen01 = new TestFocus2();
    --------TestFocus.java-----------------------------------
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import java.awt.event.WindowAdapter;
    import java.awt.event.KeyListener;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.StringTokenizer;
    import java.text.SimpleDateFormat;
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.Color;
    import java.util.Locale;
    import java.util.ResourceBundle;
    import java.awt.Container;
    public class TestFocus extends JFrame implements ActionListener
         PenKreKart aPenKreKart = null ;      
         Container ctn = null;
         JTextField f10 = null;
         JButton b10= null ;
         JTextField f1 = new JTextField() ;
         JTextField f2 = new JTextField() ;
         JButton b1 = new JButton() ;
         JFrame f20 = null;
         public TestFocus()
              //aPenKreKart = new PenKreKart(true);
              //aPenKreKart.aTemelPencere.setVisible(false);
              getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
              getContentPane().add(f1);
              getContentPane().add(f2);
              getContentPane().add(b1);
              pack();
              setVisible(true);
              b1.addActionListener(this);
         public void actionPerformed(ActionEvent e)
              if(e.getSource() == b1)
                   pencere_islemi();
         // pencere koyma k?sm? .. begin                               
         public void pencere_islemi() {     
              ctn = this;
              ctn.setEnabled(false);
              TestFocus2 fpen = new TestFocus2();
              //aPenKreKart.aTemelPencere.setVisible(true); //buras?          
              //aPenKreKart.aTemelPencere.addPenHesapListener(new PenHesapListener() {
              fpen.addPenHesapListener(new PenHesapListener() {
                        // metod      tamam_actionPerformed begin...          
                        public void tamam_actionPerformed(java.util.EventObject newEvent) {
                             ctn.setEnabled(true);
                             ctn.requestFocus();
                             // Problem is when we comment the below line it works .....
                             f1.requestFocus();
                             System.out.println("tamam");
                        // metod      tamam_actionPerformed end...          
                        // metod      iptal_actionPerformed begin...          
                        public void iptal_actionPerformed(java.util.EventObject newEvent) {
                             ctn.setEnabled(true);
                             ctn.requestFocus();
                             System.out.println("iptal");
                        // metod      iptal_actionPerformed begin...          
         // pencere koyma k?sm? .. end                               
         public static void main(String x[])
              TestFocus gen01 = new TestFocus();

  • Calling1.4.1 signed applet from Javascript causes keyboard/focus problems

    Pretty sure there's a JRE bug here, but I'm posting to forums before I open one in case I'm missing something obvious :-)
    This issue may be specific to IE, I haven't tested elsewhere yet. Our web application is centered around a signed applet that is initialized with XML data via Javascript. We first noticed the problem when our users started upgrading from the 1.3.x plug-in to the 1.4.x plug-in. The major symptom was that shortcut keys stopped working. I debugged the problem off and on for about a month before I boiled it down to a very simple program that demonstrates the issue (included below). Basically, the program has a function that adds a JButton to a JPanel and registers a keyboard listener (using the new DefaultKeyboardFocusManager class) that prints a message to the console. This function is called by the applet's init() method, as well as by a public method that can be called from Javascript (called callMeFromJavascript()). I also included a very simple HTML file that provides a button that calls the callMeFromJavascript() method. You can test this out yourself: To recreate, compile the class below, JAR it up, sign the JAR, and put in the same dir with the HTML file. Load the HTML file in IE 5.0 or greater, and bring the console up in a window right next to it. Now click the button that says init--you should see the small box appear inside the button that indicates it has the focus. Now press some keys on your keyboard. You should see "KEY PRESSED!!!" appearing in the console. This is proper behavior. Now click the Init Applet from Javascript button. It has removed the button called init, and added one called "javascript". Press this button. Notice there is no focus occurring. Now press your keyboard. No keyboard events are registered.
    Where is gets interesting is that if you go back and make this an unsigned applet, and try it again, everything works fine. This bug only occurs if the applet is signed.
    Furthermore, if you try it in 1.3, signed or unsigned, it also works. So this is almost certainly a 1.4 bug.
    Anyone disagree? Better yet, anyone have a workaround? I've tried everything I could think of, including launching a thread from the init() method that sets up the components, and then just waits for the data to be set by Javascript. But it seems that ANY communication between the method called by Javascript and the code originating in init() corrupts something and we don't get keyboard events. This bug is killing my users who are very reliant on their shortcut keys for productivity, and we have a somewhat unique user interface that relies on Javascript for initialization. Any help or suggestions are appreciated.
    ================================================================
    Java Applet (Put it in a signed JAR called mainapplet.jar)
    ================================================================
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MainApplet extends JApplet implements KeyEventDispatcher
        JPanel test;
        public void init()
            System.out.println("init called");
            setUp("init");
        public void callMeFromJavascript()
            System.out.println("callMeFromJavascript called");
            setUp("javascript");
        private void setUp(String label)
            getContentPane().removeAll();
            test = new JPanel();
            getContentPane().add( test );
            JButton button = new JButton(label);
            test.add( button );
            test.updateUI();
            DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
        public boolean dispatchKeyEvent(KeyEvent e)
            System.out.println("== KEY PRESSED!!! ==");
            return false;
    }================================================================
    HTML
    ================================================================
    <form>
    <APPLET code="MainApplet" archive="mainapplet.jar" align="baseline" id="blah"
         width="200" height="400">
         No Java 2 SDK, Standard Edition v 1.4.1 support for APPLET!!
    </APPLET>
    <p>
    <input type="button" onClick="document.blah.callMeFromJavascript();" value="Init Applet via Javascript">
    </form>

    I tried adding the requestFocus() line you suggested... Same behavior.
    A good thought, but as I mention in my description, the applet has no trouble gaining the focus initially (when init() is called). From what I have seen, it is only when the call stack has been touched by Javascript that I see problems. This is strange though: Your post gave me the idea of popping the whole panel into a JFrame... I tried it, and the keyboard/focus problem went away! It seems to happen only when the component hierarchy is descended from the JApplet's content pane. So that adds yet another variable: JRE 1.4 + Signed + Javascript + components descended from JApplet content pane.
    And yes, signed or unsigned DOES seem to make a difference. Don't ask me to explain why, but I have run this little applet through quite a few single variable tests (change one variable and see what happens). The same JAR that can't receive keyboard events when signed, works just fine unsigned. Trust me, I'm just as baffled as you are.

  • Focus problem since jre 1.4.2_11

    Hi,
    I have a awkward focus problem with my java applet. Everything is working fine for jre 1.4.2_10 and all older jre.
    The applet is embedded in a large DHTML application running in a shell which uses the internet explorer for rendering. The applet communicates with the sorrounding java script via LiveConnect (JSObjects). We do use the static versioning, in order to determine the adaequate vm version. The controls are all based upon the swing controls, some are a bit modified.
    Since the introduction of jre 1.5 update 6 the static versioning does no longer work properly. So, when I run my applet with 1.4.2_11 and all the predecessors a strange focus problem occurs.
    When I click outside the applet (focus lost) and the click on a jscript control to get back the focus to the applet, the keyboard input does not reach the applet. The comboboxes do not work anymore. A mouse click is recognized, but the data-list which should appear is only flickering for a moment.
    The only way to get the focus back, is to make a mouseclick on a selfmade datepicker (based on swing, implemeted like a popup-window). For sure, the large DHTML application is guilty, but definitely diffrent VM versions do behave differntly.
    Does anyone has an idea, has seen similar effects or knows what has been changed in the jre between 1.4.2_10 and 1.4.2_11 ??
    Any hint is appeciated! I am lost :-(((
    cheers thorsten

    Two things: Is there a document detailing manual removal of this JRE (and indeed others); you mention different 'builds' of the same JRE, this is the first time I have read that there are sub-versions/releases of a JRE. Where do I find out the available builds of this JRE and others and how they differ?

  • Significant Computer Window Focus Problem With Verizon Access Manager 7.7.1.0 (2707e)

    With the newly released Verizon Access Manager 7.7.1.0 (2707e) there is a significant computer focus problem with it.
    What I mean by this is that if I am using ANY application on my computer with the Verizon Access Manager minimized to the Windows System Tray, something will go on with the Verizon Access Manager and it steals the window focus - I am unable to work in the other application unless I click on the application to use it again.  
    An example of this would be my typing to post a message in this forum.  Something occurs in the Verizon Access Manager and my typing is rendered useless unless I click with my mouse on the browser window to be able to use it again.
    I'm highly suspecting whenever networks are coming and going in the Access Manager is when the problem occurs.
     This problem did not exist in the previous version of the Access Manager I was using.
    This is extremely annoying - please issue a fix for this ASAP!

    I have found by not minimzing the Verizon Access Manager 7.7.1.0 (2707e) the focus problem does not occur - it appears to be a problem when the app is minimzed to the system tray.

  • JTabbedPane and removeTabAt() method

    Hello,
    I use in my application a JTabbedPane and i want allow the user to remove a tab of this JTabbedPane. When the JTabbedPane change i need to perform some traitement.
    So i use a ChangeListener to be informed of all changes of my JTabbedPane.
    But, when i removed a tab which is not in last or first position i'm not informed by the change.
    Thanks for your help.
    Guiguch

    I had the same problem. I fixed it by overriding the remove() method to fire a StateChanged event:
    tabbedPane = new JTabbedPane()
         public void remove(int tab)
              super.remove( tab );
              int after = getSelectedIndex();
              //  The selected tab remained the same after this remove, consider
              //  it a state changed
              if (after == tab)
                   fireStateChanged();
    };

  • Focus Problem on the t3i

    My t3i is having focusing problems. What can be the cause?  Can I fine to the focus like on the fullframe cameras?
    Solved!
    Go to Solution.

    Kolourl3lind wrote:
    OK I will but I just relized maybe it's because I am zooming after focusing and recomposing?
    Yep - most lenses are "varifocal" -- meaning that if you carefully focus on a subject at some specific focal length in the zoom range... then zoom to a new focal length, then your subject will no longer be accurately focus.  You must re-focus the lens.
    There are a few lenses which are "parfocal" -- mean that if you zoom the focal length after focusing, your subject will still be accurately focused.  However... VERY FEW lenses are technically "parfocal" (though some are close).
    The lenses that I'm aware of which are "parfocal" are:
    EF 16-135mm f/2.8L USM
    EF 17-40mm f/4L USM
    EF 70-200mm f/2.8L USM (only the non-IS version)
    That's it.  If you use any other lens, you have to re-focus the lens after zooming.
    But I also notice you were shooting at 1/15th sec.  That's a bit slow but you were at 18mm (which helps.)  Here's the guideline on that.
    In the 35mm days, there used to be a general guideline that if the shutter speed is equal to or faster than 1/focal-length (e.g. if shooting at 50mm the you'd want to be at least 1/50th sec.... at 70mm you'd want to be at least 1/70th or faster, etc.) would be adequate.  This number doesn't apply to your T3i, but I'll get to that in a moment.
    But there are a few caveats with that...
    First, It assumes you are actually using very good camera-holding technique and you are actually TRYING to be steady.  Good camera-holding technique means you are supporting the camera from below -- typically your left is palm-up supporting the bottom of the camera and lens and your elbow is in toward your chest/stomach.    Your body weight is centered between your legs and you have a wide stance.  This means you are not leaning so your muscles don't have to work hard to keep you upright and your arms work like a brace to support the camera to your body and of course your body is nicely balanced and stable.  
    Second, It's just a "guideline" -- not a rule.  Some people are noticeably able to be more steady than others (and if caffiene makes you jittery and you just drank a coffee... and all that sort of thing.)  And sometimes it takes a bit of practice to learn good technique.  
    Third, It's also not the same for APS-C size sensor cameras (like your T3i).  For that camera, you'd have to multiple the minimum speed by the crop factor of the camera.  For a Canon APS-C camera it's 1.6 (but if you wanted to use 1.5 that'd be pretty close.)  That means at 50mm instead of using 1/50th you'd actually have to use 1/75th (technically 1/80th if we use the 1.6 factor).  e.g. 50 x 1.6 = 80 so for 50mm we'd use 1/80th.
    If you have a lens that includes image stabilization, then you may be able to shoot a bit slower.
    Most image stabilization claims to improve lens stability by 2 to 4 "stops".  What that means it that you can reduce the speed of the shutter... two to four times slower than you'd normally need because the lens is stabilizing for you.   But more caveats apply because it's not as simple as "you get 4 stops".  The stabilization isn't a guarantee... it's just a liklihood.  If it has to be less ambitious to stabilize your shot it will be far more likely to succeed.  If it has to be more ambitious to stabilize your shot then it'll do it's best... but there's no guarantee that it will work.
    You were shooting at 18mm.  So if you are using excellent posture and camera-holding technique but don't have image stabilization and you're the "average" person trying to hold the camera steady, then we multiply 18 x 1.6 and get 28.8.  There is no 1/28.8th shuter speed so we'll round that to 1/30th (because there is a 1/30th.  
    1 stop slower than 1/30th is 1/15th.. and the image stabilization probably is adequate to get you 1 stop slower successfully.
    2 stops slower is 1/8th.  Image stabilization that claims "4 stops" will usually do well at 2 stops.  So this is less of a sure-fire thing, but it does tilt the odds in your favor.
    3 stops slower is 1/4 sec.  At this point you're pushing the image stabilization system... you'll notice that if you shoot a lot of frames, that the "keeper" rate (good shots you like) will be lower, but you'll see that you are getting some.
    4 stops slower is 1/2 sec (based on the base of 1/30th for an 18mm focal length on an APS-C size sensor camera).  If you push any image stabilized lens to 4 stops, do not expect to get a very high keeper rate.  It'll sometimes help you, but you have to accept that you're really being ambitious in your expectations.
    That's image stabilization by the numbers... take the focal length, multiply it by your crop factor (which is always 1.6 but if you want to use 1.5 because it's a bit easier to do that math in our head it's close enough), round up to the nearest shutter speed available.  If you have image stabilization you can speed up the shutter speed by 1, 2, 3, or 4 times faster... but each time you get more ambitious your odds of getting "keepers" go down (but it's still better than no image stabilization at all.)
    The summary is that your minimum shutter speed (assuming good holding technique and that you are steady, etc. etc.) with image stabilization OFF the 1/30th would be your minimum speed.  At 1/15h sec you were relying on 1 stop of image stabilization help.  The image stabilization technology in the lens is good enought that "most of the time" it probably will be able to do this (not guaranteed... just likely.)  If you were NOT using good posture and holding technique... you may be challenging your image stabilization system to try to keep up.
    Tim Campbell
    5D II, 5D III, 60Da

  • Focus problems

    for some reason my canon is having focus problems even on auto focus..what is going on??

    Yes, a lot of your problem focusing could simply be that you are trying to use the camera in too low light, if shooting indoors. It will vary depending upon the camera and the lens being used on the camera. There are some ways to get focus to work, such as using an accessory flash (or ST-E2 flash controller) that can emit a Focus Assist (as Tim mentioned in his response above).
    But, not knowing your experience with the camera and autofocus cameras in general,  I first have to suggest some general info on autofocus and how it works....
    This video on YouTube is a good place to start: http://www.youtube.com/watch?v=iAx86nblZ2g. This is the first of three half-hour videos about how the Canon AF system works. Good background info to start with. I'd recommend viewing them all, then you may be able to solve the problem yourself.
    Alan Myers
    San Jose, Calif., USA
    "Walk softly and carry a big lens."
    GEAR: 5DII, 7D(x2), 50D(x3), some other cameras, various lenses & accessories
    FLICKR & PRINTROOM 

  • JTabbedPane - traversing focus through tabs

    I would like to have focus traverse through tabs in a JTabbedPane. That is, when the focus is on the last component of a tab, hitting the key for forward focus traverse should bring up the next tab and focus on the first component on that tab. I'm already using a custom FocusTraversalPolicy on the panel containing the JTabbedPane, which handles focus traversal between the components on the tabs. This policy has no knowledge of which tab a particular component is on.
    I was hoping calling requestFocusInWindow() would automagically focus that tab, but it doesn't. Needless to say, having the focus traversal policy cycle through all the components (including those in non-selected tabs) doesn't work, either. Is there an elegant way to do this, without resorting to listening to key events, watching for the TAB key, and switching to the appropriate tab?

    Ok. here is my suggestion.
    When the focus is going to be transferred to the other tab use tabpane.setSelectedComponent(nextPanel), it will trigger traverse policy once again, but we will catch the fact that current component is JPanel and transfer it further to our field.
    Following code looks ugly:
    order.add(tf1);
    order.add(tf2);
    parentsForward.put(p,tf1);
    parentsBackward.put(p,b2);but this is a concept demonstration only, you can hide this piece inside TraversalPolicy implementation.
    Here is the full code:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class TabbedFocusExample extends JFrame  {
        public TabbedFocusExample()  throws HeadlessException {
            super("Tabbed Focus Test");
            setLayout(new FlowLayout());
            JPanel p;
            final JTabbedPane tp = new JTabbedPane();
            final JTextField tf1 = new JTextField(20);
            final JTextField tf2 = new JTextField(20);
            final JCheckBox cb1 = new JCheckBox("Option 1");
            final JCheckBox cb2 = new JCheckBox("Option 2");
            final JButton b1 = new JButton("Click me!");
            final JButton b2 = new JButton("Press me!");
         //stores real components, no container
         Vector<Component> order = new Vector<Component>();
         //stores (container,first_component_in_this_container) pair
            Map<Component,JComponent> parentsForward = new HashMap<Component,JComponent>();
         //stores (container,last_component_in_previous_container) pair
         Map<Component,JComponent> parentsBackward = new HashMap<Component,JComponent>();
            p = new JPanel(new FlowLayout());
            p.add(tf1);
            p.add(tf2);
            tp.addTab("Tab 1",p);
         order.add(tf1);
            order.add(tf2);
         parentsForward.put(p,tf1);
         parentsBackward.put(p,b2);
            p = new JPanel(new FlowLayout());
            p.add(cb1);
            p.add(cb2);
            tp.addTab("Tab 2", p);
         order.add(cb1);
            order.add(cb2);
         parentsForward.put(p,cb1);
         parentsBackward.put(p,tf2);
            p = new JPanel(new FlowLayout());
            p.add(b1);
            p.add(b2);
            tp.addTab("Tab 3", p);
         order.add(b1);
            order.add(b2);
         parentsForward.put(p,b1);
         parentsBackward.put(p,cb2);
         setFocusTraversalPolicy(new MyOwnFocusTraversalPolicy(order,parentsBackward,
                              parentsForward,tp));
            add(tp);
            pack();
            setDefaultCloseOperation(EXIT_ON_CLOSE);
        public static void main(String[] args) {
            new TabbedFocusExample().setVisible(true);
        public  class MyOwnFocusTraversalPolicy     extends FocusTraversalPolicy   {
         private Vector<Component> order;
         private JTabbedPane tabbedPane;
         private Map<Component, JComponent> parentsForward;
         private Map<Component, JComponent> parentsBackward;
            public MyOwnFocusTraversalPolicy(Vector<Component> order,Map<Component,JComponent> parentsF,
                                       Map<Component,JComponent> parentsB,JTabbedPane jtb) {
                this.order = order;
             this.tabbedPane=jtb;
             this.parentsForward = parentsF;
                this.parentsBackward = parentsB;
            public Component getComponentAfter(Container focusCycleRoot,
                                               Component aComponent) {
              JComponent nextComp = parentsForward.get(aComponent);
              if(nextComp!=null){ //aComponent is Container return first component in this Container
                   return nextComp;
                    int idx = (order.indexOf(aComponent) + 1) % order.size();
              nextComp = (JComponent)order.get(idx);
              int indexCurrent = tabbedPane.indexOfComponent(((JComponent)aComponent).getParent());
              int indexNext = tabbedPane.indexOfComponent(nextComp.getParent());
              if(indexNext!=indexCurrent){ //if next Component sits in next tab go to next tab
                   tabbedPane.setSelectedComponent(nextComp.getParent());
                    return nextComp;
         //same stuff but in opposite direction
            public Component getComponentBefore(Container focusCycleRoot,
                                                Component aComponent)  {
              JComponent prevComp= parentsBackward.get(aComponent);
              if(prevComp!=null){
                   return prevComp;
                    int idx = order.indexOf(aComponent) - 1;
                    if (idx < 0) {
                          idx = order.size() - 1;
                    prevComp = (JComponent)order.get(idx);
              int indexCurrent = tabbedPane.indexOfComponent(((JComponent)aComponent).getParent());
              int indexPrevious = tabbedPane.indexOfComponent(prevComp.getParent());
              if(indexPrevious!=indexCurrent){
                   tabbedPane.setSelectedComponent(prevComp.getParent());
                   return prevComp;
            public Component getDefaultComponent(Container focusCycleRoot) {
                return order.get(0);
            public Component getLastComponent(Container focusCycleRoot) {
                return order.lastElement();
            public Component getFirstComponent(Container focusCycleRoot) {
                return order.get(0);
    }

  • Adobe Flash Pro CS6 -- cursor and focus issues

    This is OS specific as it works fine in the Snow Leopard.
    I am having issues with nearly everything involved with switching between apps / focusing on text windows / getting the cursor to appear where I click / etc since upgrading to Mountian Lion/Mavericks while using Flash Professional CS6. 
    Example problems:
    I click on the Flash icon in the menu bar (twice because the new Mac OS's have focus problems in the dock with mission control enabled) the OS will sometimes switch to the space containing Flash (sometimes not but let's focus on the Flash focus issues). I hover over the code window, I scroll with the mousewheel down the page to where I want to edit the code, I CLICK exactly where I want to paste it, hit cmd+C -- then it pastes the code NOT THERE but instead where the cursor was before (at the top of the page)... So essentially I have to double or triple click everything in Flash all the time. I just click like crazy anymore on everything all the time, but in Flash it's really unpredictable.
    This happens on both of my work computers (both 10.8.5)
    and my Mac Pro (10.9) but not my MacBook Pro that is still extremely fortunate enough to have 10.6 on it.

    What you need is an inner Graphic symbol. What I mean by Graphic symbol is when you select all your letters and hit "F8", choose "Graphic" instead of "MovieClip." In the properties panel, you'll see that one of the sections is called "Looping." Select"play once" (the default is "Loop"). Inside that graphic should be the animation of the letters moving in from left to right.
    On the outer timeline, put a keyframe at the same frame number where the Graphic's animation ends. Change the Looping to "Single Frame" and then type in the frame number of the last frame. You can then create a motion tween that animates the graphic symbol upward at its final frame.

Maybe you are looking for

  • How do i download all my iTunes from the cloud to my new iMac?

    Hi all, I have a new iMac (and very happy), i have opened it up and entered my icloud information and all my music stored in the cloud is there but greyed out. How do I download it onto the computer? I kept getting error=5099 Can any one help? I have

  • Managing PDF's without Adobe Reader

    Now that I have a new MBP and 10.6 I'm without Adobe Reader and everything is going to "preview". How do I get long documents to open with a straight on view for every page instead of preview showing them side ways? I can get each single page to turn

  • Connecting to Oracle XE via regular 10g client - ORA-12514

    I have had the 10g client installled on my computer for a while, for developing against our company Oracle databases. I have now installed the XE database locally on my computer so I can do some local development - according to the information I've b

  • Check on level of WBS element for capital purchase PO

    Hi Experts, We are facing a problem. While creating Capital purchase PO, all WBS elements are allowed. Although, system is configured in such a way that GRN can not be done for Level 1 WBS( Parent project). We want to introduce a check at PO creation

  • How to uninstall java plugin without removing JRE completely

    how to uninstall java plugin without removing JRE completely. Hope someonce can help, all the documentation ive seen till now shows how to uninstall the Java plugin by completely removing the JRE. Also if you install JRE 1.4.1_01 and do not choose to