Article View: borland.public.jbuilder.java.language
Article #18522Cursor/focus bug?
From: Tad Frysinger
Date: Fri, 05 Jun 1998 00:00
Date: Fri, 05 Jun 1998 00:00
145 lines
5545 bytes
5545 bytes
Here is an example of some strange behavior. I'm illustrating it using
JTextArea, but I've seen the same problem with lightweight JBCL input
controls as well. I'm not sure if this is just more "general lightweight
display" bugs or what but as you can see in this example, when you select
a different item in the ListControl, I am using the subfocuschanged event
to make the associated JTextArea input control current in the CardLayout,
and then requestFocus() to that input control.
What I want to have happen is as the user moves through the ListControl,
the associated input control show and have the cursor active, ready for
input. The problem is, sometimes I see the cursor, and sometimes I
don't. Why? It appears that focus is transferred successfully, as even
if I can't see the cursor I can type and the input appears in the
control. Like I stated, I've seen this behavior in lightweight JBCL
controls as well. Heavyweight controls don't have this problem. Is
there a synchronization problem between the .show() method of the layout
manager, and whether or not the cursor displays?
package TestDB;
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import borland.jbcl.control.*;
import borland.jbcl.layout.*;
import borland.jbcl.model.*;
public class Frame3 extends JFrame {
//Construct the frame
BorderLayout borderLayout1 = new BorderLayout();
JMenuBar menuBar1 = new JMenuBar();
JMenu menuFile = new JMenu();
JMenuItem menuFileExit = new JMenuItem();
JMenu menuHelp = new JMenu();
JMenuItem menuHelpAbout = new JMenuItem();
JLabel statusBar = new JLabel();
SplitPanel splitPanel1 = new SplitPanel();
BevelPanel txtHolder = new BevelPanel();
CardLayout cardLayout1 = new CardLayout();
ListControl txtList = new ListControl();
JTextArea jTextArea1 = new JTextArea();
JTextArea jTextArea2 = new JTextArea();
JTextArea jTextArea3 = new JTextArea();
public Frame3() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.getContentPane().setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
statusBar.setText(" ");
txtHolder.setBevelInner(BevelPanel.FLAT);
txtList.setItems(new String[] {"jTextArea1", "jTextArea2",
"jTextArea3"});
txtList.addSubfocusListener(new
borland.jbcl.model.VectorSubfocusAdapter() {
public void subfocusChanged(VectorSubfocusEvent e) {
txtList_subfocusChanged(e);
}
});
jTextArea1.setText("jTextArea1");
jTextArea2.setText("jTextArea2");
jTextArea3.setText("jTextArea3");
txtHolder.setLayout(cardLayout1);
menuFile.setText("File");
menuFileExit.setText("Exit");
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fileExit_actionPerformed(e);
}
});
menuHelp.setText("Help");
menuHelpAbout.setText("About");
menuHelpAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
helpAbout_actionPerformed(e);
}
});
menuFile.add(menuFileExit);
menuHelp.add(menuHelpAbout);
menuBar1.add(menuFile);
menuBar1.add(menuHelp);
this.setJMenuBar(menuBar1);
this.getContentPane().add(statusBar, BorderLayout.SOUTH);
this.getContentPane().add(splitPanel1, BorderLayout.CENTER);
splitPanel1.add(txtHolder, new PaneConstraints("bevelPanel1",
"bevelPanel1", PaneConstraints.ROOT, 1.0f));
txtHolder.add(jTextArea1, "jTextArea1");
txtHolder.add(jTextArea2, "jTextArea2");
txtHolder.add(jTextArea3, "jTextArea3");
cardLayout1.show(txtHolder, "jTextArea1");
splitPanel1.add(txtList, new PaneConstraints("listControl1", null,
null, 0.5f));
}
//File | Exit action performed
public void fileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
//Help | About action performed
public void helpAbout_actionPerformed(ActionEvent e) {
Frame3_AboutBox dlg = new Frame3_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.show();
}
//Overriden so we can exit on System Close
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
fileExit_actionPerformed(null);
}
}
void txtList_subfocusChanged(VectorSubfocusEvent e) {
cardLayout1.show( txtHolder, (String)txtList.get( e.getLocation() )
);
txtHolder.getComponent( e.getLocation() ).requestFocus();
}
}
Thanks -
Tad
Technical Details
Message-ID:
<MPG.fe1c926dcd390f989832@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,2e5cb80ff5865a4b,start X-Google-Attributes: gidf74b3,public From: tfrysinger@earthlink.net (Tad Frysinger) Subject: Cursor/focus bug? Date: 1998/06/05 Message-ID: <MPG.fe1c926dcd390f989832@forums.borland.com> X-Deja-AN: 359870050 Organization: FreeZone Enterprises Newsgroups: borland.public.jbuilder.java.language