• Post Reply Bookmark Topic Watch Topic
  • New Topic

JcomboBox

 
rama krishnan
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to get the Focus for JComboBox (Text cursor symbol should have to come in place of Combobox)
I tried the method like requestDefaultfocus(), & requestfocus(true)
but i did not get the focus on JComboBox

For JTextField I'm using the method getCaret(), its working

can any one help me


 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
focus requests will only work after the component is 'realized' - packed or visible
a textfield in a comboBox is an editorComponent - you need to access that
if it's in a tabbedPane, focus (since about 1.4) has been a problem (not sure if fixed in recent versions)

easiest way for a solution is for you to post a sample program of your code - just enough code to compile and demonstrate the problem
 
rama krishnan
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is following code



public class TestcmbBx {
.....
......

CmbBx = new javax.swing.JComboBox();

CmbBx.setEditable(true);
CmbBx.setFont(new java.awt.Font("Arial", 0, 12));
CmbBx.setName("departNameCmbBx");
Setup_mainPanel.add(departNameCmbBx, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 40, 320, -1));


in constructor i'm calling like

public TestCmbBx() {

....
.....
cmbBx.requestDefaultFocus();
cmbBx.requestFocus(true);

}
...
....
(+ Generate code) private javax.swing.JComboBox CmbBx;

}
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try calling cmbBx.requestFocusInWindow by bundling it inside SwingUtilities.invokeLater()
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> just enough code to compile and demonstrate the problem

I can't compile the code, so I can offer no further help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!