Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to set text In Jcombobox?

807589Oct 20 2008 — edited Oct 21 2008
Guys,

is there any other way aside from SelectedIndex method to place a text in a combobox? What if, if I don't know the index of that Item how would I display that text?

I have a Form which contains the Users Information , when I try to modify a user, the jcombox will retrieve ( using addItem) all the Group Name saved in the database and at the same time it should set the Group Name of that user to the combobox as the selected text. below is my code
 public UserEditor(java.awt.Frame parent, boolean modal, UserContoller uc) {
super(parent, modal);
initComponents();
this.uc = uc;
ResultSet rs = rc.GetRoleList();
cboRoleName.removeAllItems();
try {
while (rs.next()) {
cboRoleName.addItem(rs.getString("RoleName"));

//  cboRoleName.
}
cboRoleName.revalidate();
cboRoleName.repaint();
} catch (SQLException ex) {
} finally {
rs = null;
}
cboRoleName.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

}
});
}
Thanks Guys

Edited by: vinx1127 on Oct 20, 2008 7:42 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2008
Added on Oct 20 2008
4 comments
326 views