This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.
SCJP 1.4, OCMJEA/SCEA 5.0.
Joined: May 15, 2012
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.
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.
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.
There are no new questions, but there may be new answers.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com