• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JcomboBox

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;

}
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic