Java SWT List item with long text - java

Im writing UI in Java, using SWT. I use in some places SWT List.
But when I have items in the list that their length is more than the list default width, I cannot see their whole text. not with End button in the keyboard, and not with anything else.
Here is the code that generates the List:
List lstInputs = new List( shell, SWT.V_SCROLL );
any idea?

Related

How to expand a FilteredTree after the filteration?

I have used a filtered tree in order to filter the contents.
If filter text is having some text, in this case tree is expanding properly.
But If the filter text is empty, then tree is not expanding at all.
Can some one guide me how to expand the filter tree if I the filter text becomes empty?
Also, In the beginning when Tree is having lot of data and I am expanding it by treeViewer.expandAll() then it takes lot of time to open the dialog.
So, how to handle that performance?
Code Sample
FilteredTree filterTree = new FilteredTree(parent, SWT.VIRTUAL | SWT.BORDER, new PatternFilter());
filterTree.setQuickSelectionMode(true);
treeViewer = filterTree.getViewer();
treeViewer.setContentProvider(contentProvider);
treeViewer.setInput(input);
treeViewer.setLabelProvider(new LabelProvider());
treeViewer.expandAll();

How to show the maximum number of data into swt combobox?

My SWT Combo has a lot of items and the dropdownlist always shows more data at the same time in linux platform based on display size. (yes I can scroll up and down to see all the other items)
I want the dropdown list to show items at the same time e.g. 10 items at the same time.
I used this code:
m_comboBoxViewer.getCCombo().setVisibleItemCount(10);
I am getting this exception:
org.eclipse.core.runtime.AssertionFailedException: null argument:
at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:85)
at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:73)
at org.eclipse.jface.viewers.ComboViewer.getCCombo(ComboViewer.java:182)
How can I make the dropdown list, to show limited items at the same time? Has anyone an example?
It looks like you are using a ComboViewer which is using a Combo control. You must use a CCombo control to be able to set the visible items count.
CCombo comboBox = new CCombo(parent, ... style flags ....);
m_comboBoxViewer = new ComboViewer(comboBox);

Create a right click popup menu in a text area only if it is not empty and getting the selected index

I've seen the question answered in How do I create a right click context menu in Java Swing?
and seen how I can create a menu.
However, when I associate it with the text area, it doesn't matter if it has anything written on it or not, it always shows the menu.
I use the text area to reveal how many objects I have created from a specific class (which I save in a ArrayList). What I need, is a menu that when clicking on a specific line of text, it can have the index of the object in the ArrayList and use that menu to Edit/Remove that specified object from the ArrayList.
Is that possible with a Text Area or should I use a different type of displaying component?
As an Example:
Text Area:
Object 1.
Object 2.
Object 3.
When I select , for example, Object 1 with a right click, it shows the menu with Edit and Remove. But when I dont select any of them, the menu does not show.
And when it Shows, it can access the index od the object (object 1 -> index 0, object 2 -> index 1 , etc.)
Thanks a lot for your help,
Nhekas
I use the text area to reveal how many objects I have created from a specific class
Don't use a JTextArea.
Instead I would suggest you should be using a JList. Read the section from the Swing tutorial on How to Use Lists for more information and examples.
The JList has a locationToIndex(...) method which will give you the row where the mouse was clicked. Then you can get the object from the list.

wrapping the contents of List in SWT

I have created fixed size List. If the list has one item which is bigger than the List size it self, then the item should be wrapped to multiple lines.
SWT.WRAP can't be used as it supports only Label and Text controls.
For item customization of List you need to create your own widget.
Check e.g. http://www.snip2code.com/Snippet/11489/Custom-SWT-List-Box
In this way you will have full control on the rendering of the different items
If you want to have multiple lines in labels per item in a list, then you use a table instead. See the SWT snippet "draw multiple lines in a table item" for the relevant code.
The bad news is that all items must have the same height...

adding a text editor to a swt List widget

In the eclipse plugin I am working on, I want to make editable the content of a List (org.eclipse.swt.widgets.List). However, most of the examples I have found show only how to add an item editor to either a swt Table or a Tree. Is it possible to do the same with a list ?, or should I try to replace my list with a single column table ?.
This is how I instantiate the list:
new List (theComposite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL)
Can you use JFace's TableViewer and CellEditors? That's much easier and it already does a lot of stuff for you. You only need to hide the headers and use only a single column, as you already pointed out. Then it should look like a List.

Categories