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?
Related
I have a desktop program with 3 tabs i'm building in netbeans. There is 1 text input field below the three tabs. each tab has a jtextarea component. When i type in the text input field and hit enter i want it to add that text to the textarea contained by the currently selected tab.
I've been playing around with
jTabbedPane1.getSelectedIndex()
jTabbedPane1.getTabComponentAt()
How can i use the index to reference it back to the textarea associated with that tab?
Big java noob here.
The simplest way would be to use an array of JTextArea components corresponding to the order that they appear on the JTabbedPane.
JTextArea[] textArea = new JTextArea[3];
// assign textAreas...
You could then set the text using the appropriate index:
int index = jTabbedPane1.getSelectedIndex();
textArea[index].setText(myField.getText());
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
I developed a small desktop application in Java. At some position in my UI I drag and drop a JLabel from Palette to JFrame. Later-on i remove its text by right click -> Edit Text. I did this because i am populating this label dynamically using setText() method. Now i need to reposition this Label, for this i first have to select that label and then drag n drop it to new location. But i am unable to do so because there is no text in that label and hence its not visible :(
Is there any way through which i select this label?
The easiest way is add a few spaces to a label instead of an empty string. You may also put a label inside a panel with layout like Flow or Grid (where you can set margin) and drag the panel instead. If you're using layout like Free Design, Absolute or Null, you may also manually rescale the label (selecting it through Inspector view).
I'm trying to create a vertically scrolling table within a dialog, without success. When I create the table, it auto-expands to whatever height it needs to be regardless of screen size/resolution. Lots of data creates a table that extends well below the bottom of the screen.
My code goes something like this (not verbatim, may be a type-o or two):
final Table table = new Table(parent, SWT.SINGLE |
SWT.FULL_SELECTION | SWT.SCROLL_LINE | borderStyle | orientation );
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableViewer tableView = new TableViewer(table);
// code yanked to set up the columns (movable == false,
// resiable == true, with set text, widths, and toolTipText)
tableView.setContentProvider(new ArrayContentProvider());
// BeanLabelProvider's getColumnText returns the beanDescriptor's
// getReadMethod.invoke().toString()
tableView.setLabelProvider(new BeanLableProvider(MyClass.class));
tableView.setInput(anArrayOfMyClass);
All this code lives in my dialog class's createDialogArea().
At any rate, I've tried the following:
treeView.setItemCount() trims the data, it doesn't limit the amount of data displayed.
table.getVerticalBar() returns a valid ScrollBar, and that scrollbar.getVisible() == true;?! Really? Prove it. Didn't think so. setVisible(true) does nothing.
table.setBounds()? Nope. Even after I call layout() and/or redraw().
The above was done within createDialogArea(). If I call setBounds() within MyDialog.initializeBounds() it shrinks the table and adds scrollbars (gasp!), but the dialog doesn't resize. Calling table.getParent().layout(true) resizes the table, not the dialog. Augh!
In initBounds, I have the following code:
Shell shell = getShell();
shell.setBounds(foo, bar, baz qux);
myTable.setBounds(foo, bar, baz-fudgeX, qux-fudgeY);
myTable.getVerticalBar().setVisible(true); // see, it wasn't null!
// this line doesn't seem to have any effect, I can comment it out and have
// the same apparent result.
shell.layout(true);
// If I call shell.pack() the table snaps back to its original size (huge).
Without the call to pack(), the okay/cancel buttons are clipped off the bottom of the dialog. With it, the entire exercise is a moot point.
Why do I get the feeling I'm missing something Really Basic that'll make me want to smack my forehead when someone else points it out?
What layout do you use for your Shell? Most layouts simply ask the controls for their preferred size, during a call of layout(). The preferred size of your Table is the size, where all rows can be displayed. If there's no more constraints, the layout resizes the Shell to that preferred size, which is not what you want.
To prevent this, you'll need to set a height hint for your layout on your Table. An example for that is this snippet. If you remove the line
data.heightHint = 200;
the resulting Shell is way too high.
I have a few toggle buttons to add styling to text in the form of:
JToggleButton boldButton = new JToggleButton("Bold");
boldButton.addActionListener(new StyledEditorKit.BoldAction());
boldButton.setFocusable(false);
and I also have various styling functions (color, left/right/center align, etc.). What I'm wanting to do is when I call a function (in this case, I'm wanting to basically make a new document) the toggle button is toggled to the off state, and all styling returns to default.
Currently I just set the frame name to untitled (previously the name of the document I was working with), and set the pane text to "", but this keeps all of the styling I had set in the previous document. Is there a better way to do it?
Thanks
boldButton.setSelected(false)
should be all you need.