Workaround for Ampersand in SWT Table Header - java

An ampersand in an SWT Table header will not be displayed, is there a known workaround?
I have to display an ampersand in my application and i'm looking for a workaround...
https://bugs.eclipse.org/bugs/show_bug.cgi?id=154904
if you don't want to read the full atricle just follow this example
public class TableWidget {
Display d;
Shell s;
TableWidget() {
d = new Display();
s = new Shell(d);
s.setSize(250, 200);
s.setText("A Table Shell Example");
s.setLayout(new FillLayout());
Table t = new Table(s, SWT.BORDER);
TableColumn tc1 = new TableColumn(t, SWT.CENTER);
TableColumn tc2 = new TableColumn(t, SWT.CENTER);
TableColumn tc3 = new TableColumn(t, SWT.CENTER);
tc1.setText("First&&Name"); //THESE ampersands won't be shown
tc2.setText("Last & Name"); //and HERE
tc3.setText("Address");
tc1.setWidth(70);
tc2.setWidth(70);
tc3.setWidth(80);
t.setHeaderVisible(true);
TableItem item1 = new TableItem(t, SWT.NONE);
item1.setText(new String[] { "Tim", "Hatton", "Kentucky" });
TableItem item2 = new TableItem(t, SWT.NONE);
item2.setText(new String[] { "Caitlyn", "Warner", "Ohio" });
TableItem item3 = new TableItem(t, SWT.NONE);
item3.setText(new String[] { "Reese", "Miller", "Ohio" });
s.open();
while (!s.isDisposed()) {
if (!d.readAndDispatch())
d.sleep();
}
d.dispose();
}
public static void main(String[] argv) {
new TableWidget();
}
}
and yes, of course '\u0026' won't work as well - i'm not really expecting a solution but maybe someone is smarter than i am...

Ok, right later Version might solve the problem, but we have 'oldfashioned' customers, we even produce code for java 1.6 using eclipse 3.4 (!!)
but i found a WORKAROUND as requested using an symbol that looks exactly like the one i request.... if you replace any ampersands (\u0026) with fullwidth ampersand (\uFF06) you get rid of that problem....
i found the solution on http://en.wikipedia.org/wiki/Ampersand, where they displayed alternative ampersand!
i'm sorry that i created such a mess here! thanks for your support...

Related

ScrolledCompsite in TabFolder sizes content to zero

I have the following problem:
I'm using SWT to create a GUI for my application. I have a TabFolder in which I add several TabItems and in each of those I create a ScrolledComposite that holds some content.
The TabFolder is displaying fine, however the ScrolledComposite in the TabFolder does only show it's content in the first TabItem. All other ScrolledComposites are visible themselves just fine but their content is invisible.
Here is a little code snippet that demonstrates what I am referring to:
Display display = new Display();
Shell topShell = new Shell(display);
topShell.setSize(800, 800);
topShell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
topShell.setLayout(new FillLayout());
TabFolder folder = new TabFolder(topShell, SWT.NONE);
for (int i = 0; i < 5; i++) {
TabItem item = new TabItem(folder, SWT.NONE);
item.setText("Item " + i);
ScrolledComposite scroller = new ScrolledComposite(folder,
SWT.H_SCROLL | SWT.V_SCROLL );
scroller.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
Composite content = new Composite(scroller, SWT.NONE);
content.setBackground(display.getSystemColor(SWT.COLOR_RED));
scroller.setContent(content);
scroller.setExpandHorizontal(true);
scroller.setExpandVertical(true);
item.setControl(scroller);
}
topShell.setVisible(true);
while (!topShell.isDisposed()) {
display.readAndDispatch();
}
You can tell that the content is being displayed if the area is painted red. If the content is invisible the area is blue (the background of the ScrolledComposite)
I'm not sure if that matters but this occurs on Linux Mint 18 and it appears to only happen within GTK 3 (in 2 it works just fine)
After quite some time I tracked the issue down to the following:
It turned out that the problem was that the "missing" content had a size of zero, because the layouting doesn't set the size of those.
In my case it could be fixed by removing the SWT.V_SCROLL and the SWT.H_SCROLL style constants from the ScrolledComposite. Therefore the above code written as following works as expected.
Display display = new Display();
Shell topShell = new Shell(display);
topShell.setSize(800, 800);
topShell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
topShell.setLayout(new FillLayout());
TabFolder folder = new TabFolder(topShell, SWT.NONE);
for (int i = 0; i < 5; i++) {
TabItem item = new TabItem(folder, SWT.NONE);
item.setText("Item " + i);
ScrolledComposite scroller = new ScrolledComposite(folder,
SWT.NONE);
scroller.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
Composite content = new Composite(scroller, SWT.NONE);
content.setBackground(display.getSystemColor(SWT.COLOR_RED));
scroller.setContent(content);
scroller.setExpandHorizontal(true);
scroller.setExpandVertical(true);
item.setControl(scroller);
}
topShell.setVisible(true);
while (!topShell.isDisposed()) {
display.readAndDispatch();
}
Although that causes all content to be properly sized it completely removes the ScrollBars of the ScrolledComposite which somehow is not what you want from a ScrolledComposite.
Does anyone know how to fix that or whether that is a bug (that might have been fixed in newer SWT versions)?
I've fixed bugs related to this a few months ago.
Can you try latest SWT master?
http://download.eclipse.org/eclipse/downloads/

eclipse plugin add description to table/tabfolder

I'm building a plugin for eclipse and have the following code to put a tabfolder in my view:
private void constructViewWindow(Composite parent){
final TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
terminologyTab = new TabItem(tabFolder, SWT.NONE);
grammarTab = new TabItem(tabFolder, SWT.NONE);
styleTab = new TabItem(tabFolder, SWT.NONE);
xmlTab = new TabItem(tabFolder, SWT.NONE);
terminologyTable = new Table(tabFolder, SWT.BORDER);
grammarTable = new Table(tabFolder, SWT.BORDER);
styleTable = new Table(tabFolder, SWT.BORDER);
xmlTable = new Table(tabFolder, SWT.BORDER);
addTableColumns(terminologyTable);
addTableColumns(grammarTable);
addTableColumns(styleTable);
addTableColumns(xmlTable);
terminologyTab.setControl(terminologyTable);
grammarTab.setControl(grammarTable);
styleTab.setControl(styleTable);
xmlTab.setControl(xmlTable);
}
which results in the following window:
which is very nice. But I now want to add a description/some additional information to this, something that ends up in the same spot as the '0 items' text in the Tasks view:
Since I'm not sure what this would be called, googling is a bit difficult (e.g. I've tried "add header to table", but a header is obviously something else. "Description" didn't really do the trick either). I guess one could find this in the eclipse source code somewhere, but as I'm new to Java, and diving in the eclipse sources and finding what I need will take quite some time (at least for me), anyone any ideas on how to add this additional line of text above my TabFolder?
Just add a Label to the composite before the tab folder.
private void constructViewWindow(Composite parent){
label = new Label(parent, SWT.LEFT);
// TODO set layout on the layout
label.setText("0 items");
final TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
You may need to set Layout Data on the label to make sure it is wide enough for the text.
Another way is to use the ViewForm class which lets you put controls at the corners of the page.

org.eclipse.swt.widgets.Table - add item

I want to add an item to the email column and to the remove column. How do you accomplish this?
I keep looking for a add method or something but I have no been able to find anything.
I have tried setData and redraw after setting some string but this did not work.
Here is the code I have so far:
Table emailTable = new Table(composite_2, SWT.BORDER | SWT.FULL_SELECTION);
FormData fd_table = new FormData();
fd_table.bottom = new FormAttachment(emailText, -3);
fd_table.top = new FormAttachment(0, 10);
fd_table.right = new FormAttachment(emailLabel, 481);
fd_table.left = new FormAttachment(emailLabel, 0, SWT.LEFT);
Table emailTable.setLayoutData(fd_table);
Table emailTable.setHeaderVisible(true);
Table emailTable.setLinesVisible(true);
TableColumn emailColumn = new TableColumn(emailTable, SWT.NONE);
TableColumn emailColumn.setWidth(377);
TableColumn emailColumn.setText("Email");
TableColumn removeColumn = new TableColumn(emailTable, SWT.NONE);
TableColumn removeColumn.setWidth(100);
TableColumn removeColumn.setText("Remove");
You need to create TableItems with first argument in the constructor emailTable and set their text as described in http://www.vogella.com/tutorials/SWT/article.html#swt_table:
TableItem item = new TableItem(emailTable, SWT.NONE);
item.setText (0, "test#example.org");

Set ScrollableComposite position to location

Using the SWT ScrollableComposite, is there an easy way in which to set the scrollbar position to jump in such a way that a particular element will be positioned at the top?
For example, if I had such a composite filled with 26 labels going down with the letters of the alphabet in order:
...then, say that I want to set my view to the "J" label and have the scrollbar position set like this:
(This is only example - if I really wanted to do what I am describing here, I would clearly just use a listbox or a table for my letters instead.)
This is similar to how Internet Browsers work when jumping to a specific tag within a page.
This can likely be done with a bunch of manual measurement calculations, if necessary, but my hope is that something simpler exists.
I believe you are looking for below method on ScrolledComposite
org.eclipse.swt.custom.ScrolledComposite.showControl(Control) //make it visible in view port
org.eclipse.swt.custom.ScrolledComposite.setOrigin(Point) //sets left corner coordinates, read SWT docs
Updated Answer:
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Map<String,Control> controlMap = new HashMap<String,Control>();
final ScrolledComposite scrollComposite = new ScrolledComposite(shell,
SWT.V_SCROLL | SWT.BORDER);
final Composite parent = new Composite(scrollComposite, SWT.NONE);
for (int i = 0; i <= 50; i++) {
Label label = new Label(parent, SWT.NONE);
String index = String.valueOf(i);
controlMap.put(index, label);
label.setText(index);
}
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(parent);
scrollComposite.setContent(parent);
scrollComposite.setExpandVertical(true);
scrollComposite.setExpandHorizontal(true);
scrollComposite.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle r = scrollComposite.getClientArea();
scrollComposite.setMinSize(parent.computeSize(r.width,
SWT.DEFAULT));
}
});
shell.open();
Control showCntrl = controlMap.get(String.valueOf(5));
if(showCntrl != null){
scrollComposite.setOrigin(showCntrl.getLocation());
}
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}

selection in CheckboxTableViewer on win7 is not working

i try to use an org.eclipse.jface.viewers.CheckboxTableViewer, as a component of a org.eclipse.jface.wizard.WizardPage. I created it this way:
public void createControl(Composite parent) {
composite = new Composite(parent, SWT.NULL);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
composite.setLayout(gridLayout);
setControl(composite);
/* CheckboxTableViewer */
viewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
final Table table = viewer.getTable();
GridData data1 = new GridData();
data1.grabExcessHorizontalSpace = true;
data1.grabExcessVerticalSpace = true;
data1.horizontalSpan = 2;
data1.horizontalAlignment = SWT.FILL;
data1.verticalAlignment = SWT.FILL;
table.setLayoutData(data1);
table.setHeaderVisible(true);
table.setLinesVisible(true);
checkboxColumn = new TableColumn(table, SWT.LEFT);
...
the content of the viewer is inserted dynamically by a contentprovider. Everything works fine on gnome. While testing this on windows 7 (64 and 32 bit also), i am not able to select any entries of that view. Mouseclicks just seems to have no impact on the view.
I added a mouselistener to the table, and the mouseUp-/Down event is fired, selectionChanged and doubleClick on the viewer is not fired. Anyone who can explain this behaviour to me?
thx in advance,
hage
(i already posted this question in the eclipse forum without any response yet: http://www.eclipse.org/forums/index.php/t/250953/ )
You have to add another style flag while creating the CheckboxTableViewer: SWT.FULL_SELECTION
viewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION);
You can now select rows in the table by a single clicking.

Categories