Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Table with 2 checkboxes per row
Table with 2 checkboxes per row [message #431347] Thu, 11 March 2004 08:51 Go to next message
Thomas Hofmann is currently offline Thomas HofmannFriend
Messages: 6
Registered: July 2009
Junior Member
Hi
I'm trying to setup a table with 2 checkboxes per line to let the user
edit 2 respective flags. I found a way with TableViewers using images
for on / off. However, I'd like to have real checkboxes.
With TableEditors I can put Buttons, styled SWT.CHECK, onto each
cell. This seems not to be the intention of the Editor, examples I found
used it only temporary for the currently selected row/cell and dispose it
when the cursor moves on. I didn't find ways to have the checkbox
without the editor, so I created one for each row.
This works almost, problem is: when moving (traversing w/ tab) to a row
beeing outside the visible range when the table is scrolled, the Editors do
NOT follow the scrolled position even with an explicite Table.showItem()
on FocusLost of the checkboxes. Ordinary cells with only Text DO follow ...
Thanks for any help
Thomas
Re: Table with 2 checkboxes per row [message #431352 is a reply to message #431347] Thu, 11 March 2004 14:48 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
I think this was just fixed. If not, please enter a bugzilla report (with a
stand alone snippet). Thanks.

"Thomas Hofmann" <thomas.hofmann@bedag.ch> wrote in message
news:c2p93h$82s$1@eclipse.org...
> Hi
> I'm trying to setup a table with 2 checkboxes per line to let the user
> edit 2 respective flags. I found a way with TableViewers using images
> for on / off. However, I'd like to have real checkboxes.
> With TableEditors I can put Buttons, styled SWT.CHECK, onto each
> cell. This seems not to be the intention of the Editor, examples I found
> used it only temporary for the currently selected row/cell and dispose it
> when the cursor moves on. I didn't find ways to have the checkbox
> without the editor, so I created one for each row.
> This works almost, problem is: when moving (traversing w/ tab) to a row
> beeing outside the visible range when the table is scrolled, the Editors
do
> NOT follow the scrolled position even with an explicite Table.showItem()
> on FocusLost of the checkboxes. Ordinary cells with only Text DO follow
....
> Thanks for any help
> Thomas
>
>
>
Re: Table with 2 checkboxes per row [message #432041 is a reply to message #431352] Mon, 15 March 2004 14:52 Go to previous message
Thomas Hofmann is currently offline Thomas HofmannFriend
Messages: 6
Registered: July 2009
Junior Member
OK, I found it, https://bugs.eclipse.org/bugs/show_bug.cgi?id=49667
Meanwhile I discovered the attached solution (thanks Horst!), which
basically does
the same. However it looks a bit like a handcraft workaround... ;-)
Thanks, Thomas
---
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class Main {

Table table;
Shell shell;
List tableEditors = new ArrayList();

public static void main(String[] args) {
new Main().run();
}

public void run() {
Display display = new Display();
shell = new Shell(display);
shell.setText("CheckBoxes Test");
shell.setLayout(new FillLayout());
setupTable();
setupEditors();
shell.pack();
shell.open();
shell.setSize(430, 100);
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

private void setupTable() {
table = new Table(shell, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
table.setLinesVisible(true);
table.setHeaderVisible(true);
for (int i = 0; i < 2; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
column.setText("Column " + i);
column.setWidth(200);
}
for (int i = 0; i < 12; i++) {
TableItem item = new TableItem(table, SWT.NONE, i);
item.setText(new String[]{"text " + i, "checkbox " + i});
}
table.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent ev) {
// for the last line
int index = table.getSelectionIndex();
if (index < 0) { // just opened
table.select(index = 0);
}
((TableEditor)tableEditors.get(index)).getEditor().setFocus( );
}
});
}

private void setupEditors() {
TableItem[] items = table.getItems();
for (int i = 0; i < items.length; i++) {

final TableEditor editor = new TableEditor(table);
tableEditors.add(editor);

Button checkBox = new Button(table, SWT.CHECK);
checkBox.setBackground(table.getBackground());
checkBox.setText(items[i].getText(1));

editor.grabHorizontal = true;
editor.setEditor(checkBox, items[i], 1);

final int line = i;
checkBox.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
table.select(line);
table.showSelection();
Iterator iter = tableEditors.iterator();
while (iter.hasNext()) {
((TableEditor)iter.next()).layout();
}
}
});
}
}

}

----
"Steve Northover" <steve_northover@ca.ibm.com> schrieb im Newsbeitrag
news:c2ptvh$3mt$1@eclipse.org...
> I think this was just fixed. If not, please enter a bugzilla report (with
a
> stand alone snippet). Thanks.
>
> "Thomas Hofmann" <thomas.hofmann@bedag.ch> wrote in message
> news:c2p93h$82s$1@eclipse.org...
> > Hi
> > I'm trying to setup a table with 2 checkboxes per line to let the user
> > edit 2 respective flags. I found a way with TableViewers using images
> > for on / off. However, I'd like to have real checkboxes.
> > With TableEditors I can put Buttons, styled SWT.CHECK, onto each
> > cell. This seems not to be the intention of the Editor, examples I found
> > used it only temporary for the currently selected row/cell and dispose
it
> > when the cursor moves on. I didn't find ways to have the checkbox
> > without the editor, so I created one for each row.
> > This works almost, problem is: when moving (traversing w/ tab) to a row
> > beeing outside the visible range when the table is scrolled, the Editors
do
> > NOT follow the scrolled position even with an explicite Table.showItem()
> > on FocusLost of the checkboxes. Ordinary cells with only Text DO follow
> ...
> > Thanks for any help
> > Thomas
Previous Topic:Launching new browser windows from browser control
Next Topic:Strange Behavior on "Open Declaration"
Goto Forum:
  


Current Time: Fri Sep 20 06:50:46 GMT 2024

Powered by FUDForum. Page generated in 0.04914 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top