I'm interested in populating a ComboViewer with a list of objects.
I know JFace has some nice features that support that, but what if I want to make the first entry in the ComboViewer something like
<Select Connection>
or some other dummy entry that doesn't have an object associated to it? Is there any simple generic solution to it?
You could do this with the TableCombo widget from the Nebula project. You can a create TableComboViewer with input, selection listeners etc. but also set the text of the combo independently from the current selection.
TableComboViewer viewer = ...
...
viewer.getTableCombo().setText("...");
I use this in a current project. However the TableCombo is in alpha state, but in my application it works quite fine.
AFAIK you can't do it out of the box. You can write you own LabelProvider to do this, or you may want to switch to something like a ListViewer in a popup window, and use the List's headers to display your special first element.
Related
I've created a Java Application Project in Netbeans. This project has the main class JFrame form. There is, inter alia, Combo Box. I need to add a quadratic function to this Combobox. And I really don't want to use for squared anything like this
^2 .
I've thought, that function might be represented by ,for example, .png file.(Like setting icon of buttons).
Is it possible to add a picture to the model of Combo Box?
Can be model of Combobox different than String?
Or any idea, how to add a function to the Combo Box without ^ or _ ?
I have this idea for few days, but I really don't know how to solve this.
The short answer is "yes".
The responsibility for displaying the value in the combo box comes down to the ListCellRenderer
Take a look at How to use Combo Boxes for details and Providing a Custom Renderer for specifics
Image from How to use Combo Boxes trail
Of course, how you achieve this is entirely up to you. I would encourage you to put something easily identifiable in the model and then let the renderer figure out how to render it. This is kind of important as you will need to know what the user has selected and identify it at some stage, and an Image might not be the best solution for this.
Hey i want to create a thumbnail viewer, for my app, i want something similar to this.
I was wondering if there is a pre-existing component that can display thumbnails (FREE), or i was considering to use a JTable, with a custom cell renderer.
What do you think, what would be the best way.
It will be used to display images, keep in mind that i must be able to select individual and multiple files to perform actions on them.
thx in advance.
A JList would probably be better than a JTable. You can use a "horizontal wrap" style. You can always create a custom renderer for the list as well.
I'm programming a GUI in Java using the Vaadin framework having a question about adjusting the behaviour of a drop down list.
What is the correct property action to make a drop down list of the type Select none-writeable. That is, when selected I don't want the "write-marker" to flash in the list expecting input but rather have the drop down list expand on such an action.
I've tried with searchDropDown.setReadOnly(true); but that turned off the drop down behaviour completely...
Anyone have any ideas...? =)
Thanks!
Try using a NativeSelect instead of ComboBox?
Is there a way to store both key and value in an item in a SWT Combo/List? If not, are there SWT components that look like a Combo and/or List that do?
Yes, there is. Use the setData( String key, Object value ) method.
Take a look at JFace, especially the viewers. The ComboViewer should be the right tool for the job.
Basically, the viewers are there for mapping between your domain objects and SWT components. There is even data binding functionality available which saves you a lot of boiler-plate code.
JFace Structured Viewers are the answer. Learn more about them here. They have a special combo implementation.
My current application uses a JList and everything is well (the only customization I did was to set the italic font on some of the rows).
Now I want to "upgrade" the user interface and instead of just labels in the List, I want a checkbox and a text field to be able to update the entry.
I started changing the code and adding a custom cell renderer and a custom cell model. My current problem is that the JPanel that the cell renderer is returning is not using the whole width of the container, so several list items are actually shown on the same line.
But now, I am wondering whether I should just change the whole thing to use JTable. I still need to add / remove items in the list though...
Any suggestion which one is better ? and if going with the JList, how should I go about fixing my current problem ?
In my experience using JTable is usually easier as it allows more complex data and functionality out-of-the-box. Usually when I try to do something the JList can't do, I just switch to JTable without a second thought. What you want sounds like something that should be pretty trivial to implement in a table. I suggest you try it out with some mock data to see if you can make it look and work the way you like (especially in case you want it to look like a list).
Try calling setLayoutOrientation(JList.VERTICAL) on your JList. That will restrict JList to a single column.