🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Pb with focus in JTextField

#12600
From: Steve Waters
Date: Thu, 10 Dec 1998 00:00
139 lines
4242 bytes
Bonjour Anne,

What you have done is correct, i have done it mysoft, I can only suggest that
there must be something somehow wrong with you code, but with the information
below it impossible for me to say.


I just tried this out, and it should help you good luck

Steve





//Title:       Your Product Name
//Version:
//Copyright:   Copyright (c) 1998
//Author:      Steve Waters
//Company:
//Description: Your description
package untitled30;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import com.sun.java.swing.*;

//import com.sun.java.swing.UIManager;
public class Applet1 extends JApplet {
  boolean isStandalone = false;
  JPanel jPanel1 = new JPanel();
  JTextField jTextField1 = new JTextField();
  JTextField jTextField2 = new JTextField();
  JTextField jTextField3 = new JTextField();

  //Construct the applet

  public Applet1() {
  }
//Initialize the applet

  public void init() {
    try {
    jbInit();
    }
    catch (Exception e) {
    e.printStackTrace();
    }
  }
  //static {
  //  try {
  //    //UIManager.setLookAndFeel(new
com.sun.java.swing.plaf.metal.MetalLookAndFeel());
  //    //UIManager.setLookAndFeel(new
com.sun.java.swing.plaf.motif.MotifLookAndFeel());
  //    UIManager.setLookAndFeel(new
com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
  //  }
  //  catch (Exception e) {}
  //}
//Component initialization

  private void jbInit() throws Exception {
    this.setSize(400,300);
    jPanel1.setLayout(null);
    jTextField1.setText("");
    jTextField1.setBounds(new Rectangle(23, 21, 129, 33));
    jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(FocusEvent e) {
        jTextField1_focusGained(e);
      }
    });
    jTextField2.setText("jTextField2");
    jTextField2.setBounds(new Rectangle(46, 87, 143, 33));
    jTextField3.setText("jTextField3");
    jTextField3.setBounds(new Rectangle(81, 180, 139, 31));
    this.getContentPane().add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jTextField1, null);
    jPanel1.add(jTextField2, null);
    jPanel1.add(jTextField3, null);
  }
//Get Applet information

  public String getAppletInfo() {
    return "Applet Information";
  }
//Get parameter info

  public String[][] getParameterInfo() {
    return null;
  }

  void jTextField1_focusGained(FocusEvent e) {
    jTextField1.setBackground(new Color(255,0,0));
  }
}







Anne JANSSENS wrote:

> Need Help :(
>
> In a JFrame, on a panel I have many JTextField, I give the focus to the
> first Textfield by calling
> mytextfield.requestFocus();
>
> I have implementing a focus listener that
> - in focus gained, change the color of the textfield
> - in focus lost, put the initial color
>
> I change the focus of my component by exiting from that component with tab,
> enter, or arrow !
> And I request one more time that the next component get the focus by
> requestFocus()!
> And so on
>
> The problem is that the second component don't get any caret, and it color
> don't change, but i am sure
> that the second component get the focus !
>
> If  I open a window in front of this second component and I close that
> window, the carret appears, and the color too
> on the second component, but also still in the first one!
>
> It is a problem of painting, so I have called the repaint method in the
> focus gained, and lost to refresh the paint, but
> no way, it does nothing !
>
> Hints or solutions will be very appreciated ! Anne
>
> I join a snapshop of my frame to understand the problem :
>
>  [Image]
Technical Details
Message-ID: <367079F9.FDFD3C85@bellsouth.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <72grv9$e6p15@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,c338936232ff7c59,start
X-Google-Attributes: gid111d45,public
From: Steve Waters <steve_w@bellsouth.net>
Subject: Re: Pb with focus in JTextField
Date: 1998/12/10
Message-ID: <367079F9.FDFD3C85@bellsouth.net>
X-Deja-AN: 421021627
Content-Transfer-Encoding: 7bit
References: <72grv9$e6p15@forums.borland.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing