Wrap exceeding content of combo box in available space? - java

I have been working on an SWT project. I have a combo box whose values are set through database. I have set a fixed size for combo box but when a long string is set as an item for it, the width of combobox exceeds out of set size. I want the combo box to wrap the content by shifting the exceeding string to next line.
Here's my code:
String items[] = {"A","B","WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW","C"};
Combo combo =new Combo(comp, SWT.WRAP);
combo.setItems(items);
combo.select(0);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
combo.setLayoutData(gridData);

You will not be able to achieve WRAP in SWT Combo.
You may want to look at
http://www.eclipse.org/nebula/widgets/tablecombo/tablecombo.php
I am not sure TableCombo supports multi line items. But you can achieve that by using OwnerDrawLabelProvider on TableViewer.

Combo does not support SWT.WRAP. What you are describing is not possible through any of the standard widgets. This will have to be a completely custom control.

If you are making use of the GridLayout on the parent composite, GridData with widthHint can be set as layout data to the Combo control. However, dropdown/hints would still overflow the set width

Related

Remove Scrollbar from ComboBox JavaFX

I want to remove the scrollbar from the combobox and hence increase the height of the combobox when it is open. Meaning, i want to see all the items without scrolling.
Thanks!
If you don't want scrolling and the list options will remain few in number and relatively constant, you might actually want the ChoiceBox UI element. It has relatively the same function as the ComboBox without the scrolling capability.
...
choice boxes, the UI controls that provide support for quickly selecting between a few options.
Check out the Oracle docs on how to use them -- it's very similar to the ComboBox.

Move to specific position in TextFlow JavaFX

I'm having a TextFlow inside a StackPane which is inside a ScrollPane. I'm adding text with different colors to this TextFlow
Text txt = new Text(msg);
txt.setFill(Paint.valueOf(color));
txtFlow.getChildren().add(txt);
I want to scroll to a some specific point in the textflow.
e.g. First text that is in blue color.
I know I can get the text and check the color. But how can I scroll down to that specific position?
Can I achieve that sort of functionality through the TextFlow?
Simply I'm trying to build up a diff view in JavaFX. And want to travel through the diffs.
I would take a ListView and put some stackpanes or directly the texts in it.
Text content = new Text("Custom Text");
content.setFill(Color.valueOf(yourcolor));
ListView<Text> list = new ListView<Text>();
list.add(content);
Because...
there's a void scrollTo() where you can scroll to the item directly by the Text object or to the item by the index (int).
To get a transparent background on the listview you can use:
list.setStyle("-fx-background-color: transparent;");
I hope this helped you.
I'm sorry if I missunderstood your question.
Peace
Use one of the free styledtext-editors - they all are using ListView or VirtualView internally. See https://github.com/TomasMikula/RichTextFX/wiki/JavaFX-Controls-for-Code-Editing for examples

Label text does not wrap up in a FieldEditorPreferencePage window

I'm using a FieldEditorPreferencePage for my Preference Window. I'm also using FieldEditor Abstract base class for all my field editors in the Preference window.
I have 3 radio buttons and as the user clicks on the radio button a text will be displayed at the bottom of the window educating the user on the selected options, My problem is that, the text of the label is very long and does not fit into the Preference window. I want the label text to wrap up automatically as the size of the window grows or shrinks, I tried every possible thing to wrap up the text but instead the text gets lost, for example I have tried :
GridData g = new GridData(GridData.FILL_BOTH);
g.widthHint = 200;
Label l = new Label(getFieldEditorParent(), SWT.BEGINNING | SWT.WRAP);
l.setLayoutData(g);
l.setText("Long Msg");
getFieldEditorParent() returns a parent composite for a field editor.
Apart from the above code, I have also tried all the other possible combinations of parameters for GridData and the Label, but the result in the UI part remains the same(text will get lost if the size of the text exceeds the size of the window). I can set the size of the window to fit the text, but that is hard-coding.
How can I possibly wrap up the label text as the window's size grows and shrinks?
Is this an issue with FieldEditorPreferencePage? Is there a conflict using a label in a preference page? Someone please explain in brief as to why this happens?

Multiline feature in an editable jtable cell

I want to have multiline feature for JTable cells. Wherein the cell automatically expands and shrinks itself when user writes or deletes text in/from cell. I have set columns width, but it doesnt automatically adjust itself according to user's input, rather text beyond the width are not seen at all, but i have a requirement to fix on the width. Can anyone help me with this, to have self adjusting and multiline feature for jtable cell. Would be very thankful.
Thanks in advance.
Several steps:
implement a custom renderer using a JTextArea as rendering component
implement a custom editor using a JTextArea inside a JScrollPane as editing component
add logic (aka: TableModelListener) which updates JTable's individual rowHeight based on the renderer's preferred size on receiving a change notification

How do I resize the dropdown of a combobox?

Background:
I am doing some UI work in an eclipse environment where I fill a combo control with some values. The string values have an different length and often a length greater than the combo width and the width of the parent composite.
Problem:
When I open the dropdown list, the width of the list is greater than the width of the parent composite and the user could not see the complete value of the list entry.
I have tried to use the "setTextLimit" option, but without success. For me it is perfectly adequate if I could set the width of the dropdon list with a constant value.
Code example:
this.mComponentName = new Combo (lComponentComposite, SWT.BORDER);
this.mComponentName.setTextLimit(COMBO_TEXT_LIMIT);
GridData componentNameGridData = new GridData();
componentNameGridData.widthHint = 166;
this.mComponentName.setLayoutData(componentNameGridData);
this.mComponentName.addSelectionListener(this.mComboSelectionAdapter);
this.mComponentName.addKeyListener(this.mComboKeyAdapter);
Greetings
dirk
While creating a combobox specify Horizontal scroll also
this.mComponentName = new Combo (lComponentComposite, SWT.BORDER|SWT.H_SCROLL);
This will not let the text overflow
That is really a good question. After digging through developer forums and even the source code, I lean towards saying it is not possible.
I solved the problem temporarily by switching to a CCombo, but I do not like the solution as I believe one of SWT's strength is in using native widgets, and the CCombo does not look as good (at least on Win7 and OS X).
When you select a drop-down combo box or drop-down list box to size it, only the right and left sizing handles are active. Use these handles to set the width of the box as it is displayed initially.
Choose the drop-down arrow at the right of the combo box.
The outline of the control changes to show the size of the combo box with the drop-down area extended.
Use the bottom sizing handle to change the initial size of the drop-down area.
Choose the drop-down arrow again to close the drop-down portion of the combo box.
Have you tried passing some other value as your second parameter in your Combo initialization (first line) ? Something other than SWT.BORDER?
I've tried finding out if it is possible to display strings in multiple rows (as a single combo box item), but with no success. This would reduce the width of your items. Try adding \n to a couple of strings that you add to the combo box, and see if it will work. If it works, you can automate this process later by parsing through the string, and checking whether the space character count gets to high and adding \n after every fifth or sixth blank character. I think codejammer's suggestion is the best one, but I can't upvote yet.
Partially solved the problem adding to item names some spaces (have set the number of spaces by trial and error). Now combo is wider and all texts are visible, however horizontal scroll is visible, too.
String p = " ";
combo.add("Long.... item name 1"+p);
combo.add("Long item name ..... 2"+p);
...
Another soultion is resize combo when it gain focus and restore size after lost focus. Example below.
final Point p = combo.getSize();
combo.addFocusListener(new FocusListener() {
#Override
public void focusLost(FocusEvent e) {
((Control) e.getSource()).setSize(p);
}
#Override
public void focusGained(FocusEvent e) {
((Control) e.getSource()).setSize(new Point(400, p.y));
}
});
combo.setPreferredSize(new Dimension(FIX_WIDTH, FIX_HEIGHT));
Try this
JComboBox CB = new JComboBox();
CB.setPreferredSize(new Dimension(int, int));
p.add(CB);// which p is a JPanel

Categories

Resources