🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #13094

Re: Simple focus questions (with source code) - frametabulacao.java (0/1)

#13094
From: Martin Anders
Date: Mon, 21 Sep 1998 00:00
167 lines
6714 bytes
Hi Joao,

as a workaround of this problem I've disabled the Swing Focus Manager (because it's maybe corupted)
and used the default AWT Focus Manager instead. In order to do so you have to change your code:

import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import borland.jbcl.layout.*;

//The AWT Focus Manager uses the order you added the components as the tab order, you allready used
that order, you only //have to disable the Swing Focus manager, either in the jbinit() method or in
the constructor by adding the following line:
//com.sun.java.swing.FocusManager.disableSwingFocusManager();

public class FrameTabulacao extends JFrame {
   JTextField jTextField1 = new JTextField();
   XYLayout xYLayout1 = new XYLayout();
   JTextField jTextField2 = new JTextField();
   JTextField jTextField3 = new JTextField();
   JTextField jTextField4 = new JTextField();
   JButton jButton1 = new JButton();
   JButton jButton2 = new JButton();

   //disable the Swing Focus Manager

   public FrameTabulacao() {
      try  {
         jbInit();
        //this disables the Swing Focus Manager
        com.sun.java.swing.FocusManager.disableSwingFocusManager();
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   }



Martin




Joao Mauricio wrote:

> Hi all,
>
>         I'm trying to change the tab order of my frame.
>         My frame have 4 (four) JTextField's and 2 (two) JButton's, like this:
>
>    jTextField1     jButton1
>    jTextField2     jButton2
>    jTextField3
>    jTextField4
>
>         The default order is jTextField1, jButton1, jTextField2, jButton2,
> jTextField3, jTextField4.
>
>         I'm trying to change this to jTextField1, jTextField2, jTextField3,
> jTextField4, jButton1, jButton2.
>
>         I used the method setNextFocusableComponent(Component). When I hit the TAB
> key I receive the message:
>
> Exception occurred during event dispatching:
> java.lang.ArrayIndexOutOfBoundsException: 6 > 5
>         at java.util.Vector.insertElementAt(Compiled Code)
>         at com.sun.java.swing.DefaultFocusManager.childrenTabOrder(Compiled Code)
>         at
> com.sun.java.swing.DefaultFocusManager.getComponentAfter(DefaultFocusManager.java:225)
>         at
> com.sun.java.swing.DefaultFocusManager.getNextComponent(DefaultFocusManager.java:162)
>         at
> com.sun.java.swing.DefaultFocusManager.getFocusableComponentAfter(DefaultFocusManager.java:137)
>         at
> com.sun.java.swing.DefaultFocusManager.focusNextComponent(DefaultFocusManager.java:88)
>         at
> com.sun.java.swing.DefaultFocusManager.processKeyEvent(DefaultFocusManager.java:76)
>         at com.sun.java.swing.JComponent.processKeyEvent(Compiled Code)
>         at java.awt.Component.processEvent(Compiled Code)
>         at java.awt.Container.processEvent(Compiled Code)
>         at java.awt.Component.dispatchEventImpl(Compiled Code)
>         at java.awt.Container.dispatchEventImpl(Compiled Code)
>         at java.awt.Component.dispatchEvent(Compiled Code)
>         at java.awt.LightweightDispatcher.processKeyEvent(Container.java:1421)
>         at java.awt.LightweightDispatcher.dispatchEvent(Compiled Code)
>         at java.awt.Container.dispatchEventImpl(Compiled Code)
>         at java.awt.Window.dispatchEventImpl(Compiled Code)
>         at java.awt.Component.dispatchEvent(Compiled Code)
>         at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
>
>         What I need to do ?
>
> Thanks in advance,
> Joao Mauricio
>
> -------------- Source Code -------------------------------
> package cetip.teste;
>
> import java.awt.*;
> import java.awt.event.*;
> import com.sun.java.swing.*;
> import borland.jbcl.layout.*;
>
> public class FrameTabulacao extends JFrame {
>    JTextField jTextField1 = new JTextField();
>    XYLayout xYLayout1 = new XYLayout();
>    JTextField jTextField2 = new JTextField();
>    JTextField jTextField3 = new JTextField();
>    JTextField jTextField4 = new JTextField();
>    JButton jButton1 = new JButton();
>    JButton jButton2 = new JButton();
>    public FrameTabulacao() {
>       try  {
>          jbInit();
>       }
>       catch (Exception e) {
>          e.printStackTrace();
>       }
>    }
>
>    private void jbInit() throws Exception {
>       this.getContentPane().setLayout(xYLayout1);
>       jTextField1.setText("jTextField1");
>       jTextField1.setNextFocusableComponent(jTextField2);
>       jTextField2.setText("jTextField2");
>       jTextField2.setNextFocusableComponent(jTextField3);
>       jTextField3.setText("jTextField3");
>       jTextField3.setNextFocusableComponent(jTextField4);
>       jTextField4.setText("jTextField4");
>       jTextField4.setNextFocusableComponent(jButton1);
>       jButton1.setText("jButton1");
>       jButton1.setNextFocusableComponent(jButton2);
>       jButton2.setText("jButton2");
>       jButton2.setNextFocusableComponent(jTextField1);
>       this.getContentPane().add(jTextField1, new XYConstraints(17, 32, 207,
> -1));
>       this.getContentPane().add(jTextField2, new XYConstraints(17, 63, 212,
> 26));
>       this.getContentPane().add(jTextField3, new XYConstraints(17, 105, 208,
> 29));
>       this.getContentPane().add(jTextField4, new XYConstraints(15, 151, 217,
> 24));
>       this.getContentPane().add(jButton1, new XYConstraints(281, 30, 100, 28));
>       this.getContentPane().add(jButton2, new XYConstraints(280, 69, 101, 28));
>       this.getRootPane().setDefaultButton(jButton1);
>    }
>
>    public static void main(String args[]) {
>       FrameTabulacao frame = new FrameTabulacao();
>       frame.setSize(500, 300);
>
>       frame.addWindowListener(new WindowAdapter() {
>          public void windowClosing(WindowEvent e) {
>             System.exit(0);
>          }
>       });
>
>       frame.setVisible(true);
>    }
> }
>
> ---------------------------------------------------
> Joao Mauricio
>
> All opinions here are mine and mine alone.
Technical Details
Message-ID: <3606195E.7B6F0523@ddsynergy.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3602be51.8102444@forums.inprise.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,8340ba73575c5173
X-Google-Attributes: gid111d45,public
From: Martin Anders <m_anders@ddsynergy.de>
Subject: Re: Simple focus questions (with source code) - frametabulacao.java (0/1)
Date: 1998/09/21
Message-ID: <3606195E.7B6F0523@ddsynergy.de>
X-Deja-AN: 393228818
Content-Transfer-Encoding: 7bit
References: <3602be51.8102444@forums.inprise.com>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing