This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Editing the combo box dropdown(popup) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Editing the combo box dropdown(popup)" Watch "Editing the combo box dropdown(popup)" New topic
Author

Editing the combo box dropdown(popup)

veenu rohatgi
Greenhorn

Joined: May 15, 2012
Posts: 2
i am working on bringing up a combo box which can be edited . This combo box must be editable in the last index of the dropdown.popup of the combo box.All the other list elements must be displayed as usual.

On one of the list index(preferably the last index) of the popup , I need to have a text box which needs to editable. The initial text on the text field shall be blank.

I used the followng code using renderer which gives me a text box but it is till uneditable as the return type of the renderer is JLabel.

Also the drop down holds a JList and does not have a renderer like a table (which has table cell rendered to make a particular cell editable.

Tried using the Renderer code mentioned below which displays a text field @ first index, but it is not editable::



Please help me with some suggestions to resolve this issue.
Thanks.
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

Hi Veenu,
Welcome to the Ranch!

It is not clear to me what you are trying to achieve. Why do you want the 'last' index to be editable?
Normally, in such cases, we would create a JComboBox and call the setEditable(true) method. This makes the combobox editable. So, the user can either choose one of the entries from the popup or enter a new value in the text box.
Also, a 'Renderer' is used to control how a value is 'displayed' and not edited...editing is controlled by using custom editors.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
veenu rohatgi
Greenhorn

Joined: May 15, 2012
Posts: 2
Hi ,

Thanks for your reply.

This was a product requirement to make the last idex of the combo box pop up list to be editable.

Using setEditable(true) makes the it editable in the first element.

So , trying out ways to achieve this.

Thanks


Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

First off, to get a clear understanding of what a renderr can or cannot do/be, I suggest you go through the tutorial on How to Use Tables (linked from the JTable API) which has a section on Concepts: Editors and Renderers.

Short of writing a very complex custom UI delegate for JComboBox, I don't see any way to fulfill this exact requirement. A workaround might be to add two JComboBoxes, one editable and the other not, to a JPanel with a CardLayout, and swap the cards depending on the selected index. At a glance, it looks rather like the two combo boxes could even share the same model, which would make it automatic that they remain in sync with each other.

Also...
Tried using the Renderer code mentioned below which displays a text field @ first index
The code shows otherwise.
That's the second index. List indexes, like most things Java (except JDBC), are zero based.


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Editing the combo box dropdown(popup)
 
Similar Threads
actionevent in jcombobox of jtable
Color in JComboBox
show multiple image Using Jlist
Combobox lookup in a Jtable
JComboBox and "long" items rendered via HTML