Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Single column table possible?
Single column table possible? [message #443494] Sat, 25 September 2004 12:45 Go to next message
Craig Setera is currently offline Craig SeteraFriend
Messages: 54
Registered: July 2009
Member
I would like to take advantage of the Table CellEditor support and such,
but what I have essentially is a list of values. It seems that no
matter what I do, I can't seem to make a single column table. No matter
what, I always seem to end up with at least two columns in the table.
This is all on the Window platform (version 3.0.1 of Eclipse). Is this
some sort of platform requirement? Is there anything else I can do to
get CellEditor-like functionality? I would even be ok with a two column
table in which the first column takes 100% of the width, but that
doesn't seem to be possible even.

Thanks for any help,
Craig
Re: Single column table possible? [message #443530 is a reply to message #443494] Mon, 27 September 2004 13:18 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Craig,

I think the following does what you want. It's based on
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet88.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup .

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
final Table table = new Table(shell, SWT.FULL_SELECTION |
SWT.HIDE_SELECTION);
table.setLinesVisible(true);
TableColumn column = new TableColumn(table, SWT.NONE);
for (int i = 0; i < 10; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText("item " + i);
}
final TableEditor editor = new TableEditor(table);
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
editor.minimumWidth = 50;
final int EDITABLECOLUMN = 0;
table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Control oldEditor = editor.getEditor();
if (oldEditor != null) oldEditor.dispose();
TableItem item = (TableItem)e.item;
if (item == null) return;
Text newEditor = new Text(table, SWT.NONE);
newEditor.setText(item.getText(EDITABLECOLUMN));
newEditor.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
Text text = (Text)editor.getEditor();
editor.getItem().setText(EDITABLECOLUMN,
text.getText());
}
});
newEditor.selectAll();
newEditor.setFocus();
editor.setEditor(newEditor, item, EDITABLECOLUMN);
}
});
shell.setSize(300, 300);
table.setBounds(10,10,200,200);
column.setWidth(table.getSize().x); // <--
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

Grant

"Craig Setera" <seterajunk@charter.net> wrote in message
news:cj3p1d$44v$1@eclipse.org...
> I would like to take advantage of the Table CellEditor support and such,
> but what I have essentially is a list of values. It seems that no
> matter what I do, I can't seem to make a single column table. No matter
> what, I always seem to end up with at least two columns in the table.
> This is all on the Window platform (version 3.0.1 of Eclipse). Is this
> some sort of platform requirement? Is there anything else I can do to
> get CellEditor-like functionality? I would even be ok with a two column
> table in which the first column takes 100% of the width, but that
> doesn't seem to be possible even.
>
> Thanks for any help,
> Craig
Re: Single column table possible? [message #443634 is a reply to message #443530] Tue, 28 September 2004 21:51 Go to previous messageGo to next message
Craig Setera is currently offline Craig SeteraFriend
Messages: 54
Registered: July 2009
Member
I was able to apply the concept to my code and it works perfectly. Thanks.

Grant Gayed wrote:
> Hi Craig,
>
> I think the following does what you want. It's based on
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet88.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup .
>
> public static void main(String[] args) {
> Display display = new Display();
> Shell shell = new Shell(display);
> final Table table = new Table(shell, SWT.FULL_SELECTION |
> SWT.HIDE_SELECTION);
> table.setLinesVisible(true);
> TableColumn column = new TableColumn(table, SWT.NONE);
> for (int i = 0; i < 10; i++) {
> TableItem item = new TableItem(table, SWT.NONE);
> item.setText("item " + i);
> }
> final TableEditor editor = new TableEditor(table);
> editor.horizontalAlignment = SWT.LEFT;
> editor.grabHorizontal = true;
> editor.minimumWidth = 50;
> final int EDITABLECOLUMN = 0;
> table.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> Control oldEditor = editor.getEditor();
> if (oldEditor != null) oldEditor.dispose();
> TableItem item = (TableItem)e.item;
> if (item == null) return;
> Text newEditor = new Text(table, SWT.NONE);
> newEditor.setText(item.getText(EDITABLECOLUMN));
> newEditor.addModifyListener(new ModifyListener() {
> public void modifyText(ModifyEvent e) {
> Text text = (Text)editor.getEditor();
> editor.getItem().setText(EDITABLECOLUMN,
> text.getText());
> }
> });
> newEditor.selectAll();
> newEditor.setFocus();
> editor.setEditor(newEditor, item, EDITABLECOLUMN);
> }
> });
> shell.setSize(300, 300);
> table.setBounds(10,10,200,200);
> column.setWidth(table.getSize().x); // <--
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) display.sleep();
> }
> display.dispose();
> }
>
Re: Single column table possible? [message #443635 is a reply to message #443530] Tue, 28 September 2004 23:33 Go to previous messageGo to next message
Paul Singleton is currently offline Paul SingletonFriend
Messages: 37
Registered: July 2009
Member
Grant Gayed wrote:

> I think the following does what you want. It's based on
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet88.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup .

This looks very useful, but after playing with it
(under NT4) I wonder why

editor.horizontalAlignment = SWT.LEFT;
and
editor.minimumWidth = 50;

are apparently redundant, and is there any way to
match the left margins in the editor and table cell
so that the cell text doesn't jump slightly left when
selected for editing?

Paul Singleton
Re: Single column table possible? [message #443706 is a reply to message #443635] Wed, 29 September 2004 14:32 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
> editor.horizontalAlignment = SWT.LEFT;
> and
> editor.minimumWidth = 50;
>
> are apparently redundant

The alignment makes the text field line up with the left side of the table
cell. The minimumWidth means that even if the column is rezzied to be less
than 50 pixels wide (or part of teh column is offscreen and can only be
reached by scrolling) then the text editor will be a minimum of 50 pixels
wide. I don't understand what is redundant about that.

> is there any way to match the left margins in the editor and table cell
> so that the cell text doesn't jump slightly left when selected for
> editing?

Currently there is no way to query what the correct spacing should be. It
differes from platform to platform and even from theme to theme. As a
result, there is no API in TableEditor to let you set the indentation
because there is no way you can get the value right.


"Paul Singleton" <paul@jbgb.com> wrote in message
news:cjcs2l$a3d$1@eclipse.org...
> Grant Gayed wrote:
>
>> I think the following does what you want. It's based on
>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet88.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup .
>
> This looks very useful, but after playing with it
> (under NT4) I wonder why
>
> editor.horizontalAlignment = SWT.LEFT;
> and
> editor.minimumWidth = 50;
>
> are apparently redundant, and is there any way to
> match the left margins in the editor and table cell
> so that the cell text doesn't jump slightly left when
> selected for editing?
>
> Paul Singleton
Re: Single column table possible? [message #443753 is a reply to message #443706] Wed, 29 September 2004 22:29 Go to previous messageGo to next message
Paul Singleton is currently offline Paul SingletonFriend
Messages: 37
Registered: July 2009
Member
Veronika Irvine wrote:

>> editor.horizontalAlignment = SWT.LEFT;
>>and
>> editor.minimumWidth = 50;
>>
>>are apparently redundant
>
>
> The alignment makes the text field line up with the left side of the table
> cell. The minimumWidth means that even if the column is rezzied to be less
> than 50 pixels wide (or part of teh column is offscreen and can only be
> reached by scrolling) then the text editor will be a minimum of 50 pixels
> wide. I don't understand what is redundant about that.

I was experimenting with different values for those two, and
nothing made any difference, even commenting them out.

I think I've figured it out: (at least for win32) you only
get an editor wider than the column if there is extra table
width to the right of the column. Craig wants a virtual
editable List, where the table appears to have exactly one
column, so this will never happen, and setting minimumWidth
is pointless. Without this, grabHorizontal = true fits the
editor to the column, and setting horizontalAlignment is
also pointless.

If you leave these fields alone and add

table.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
column.setWidth(table.getClientArea().width);
}
});

the gizmo is resizable in x and y, and looks like an editable
list whatever:

public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout( new FillLayout());
final Table table = new Table(shell, SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
table.setLinesVisible(true);
final TableColumn column = new TableColumn(table, SWT.NONE);
for (int i = 0; i < 10; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText("item " + i);
}
final TableEditor editor = new TableEditor(table);
editor.grabHorizontal = true;
final int EDITABLECOLUMN = 0;
table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Control oldEditor = editor.getEditor();
if (oldEditor != null)
oldEditor.dispose();
TableItem item = (TableItem) e.item;
if (item == null)
return;
Text newEditor = new Text(table, SWT.NONE);
newEditor.setText(item.getText(EDITABLECOLUMN));
newEditor.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
Text text = (Text) editor.getEditor();
editor.getItem().setText(EDITABLECOLUMN, text.getText());
}
});
newEditor.selectAll();
newEditor.setFocus();
editor.setEditor(newEditor, item, EDITABLECOLUMN);
}
});
table.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
column.setWidth(table.getClientArea().width);
}
});
shell.setSize(300, 300);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

Paul Singleton
Re: Single column table possible? [message #443762 is a reply to message #443753] Thu, 30 September 2004 12:56 Go to previous messageGo to next message
Craig Setera is currently offline Craig SeteraFriend
Messages: 54
Registered: July 2009
Member
Paul hit on exactly the implementation I came up with. The "concept"
that I pulled from Grant's example was setting the width of the column
directly rather than using TableLayout. It seemed that even if I told
the TableLayout to use all of the space, it never really did. I hadn't
realized that I wasn't seeing an extra column, but I was seeing the
extra space the single column wasn't filling.

What is the difference between getClientArea() and getSize()? I used
getSize() in my case and it seemed to work correctly.

Paul Singleton wrote:
>
> I was experimenting with different values for those two, and
> nothing made any difference, even commenting them out.
>
> I think I've figured it out: (at least for win32) you only
> get an editor wider than the column if there is extra table
> width to the right of the column. Craig wants a virtual
> editable List, where the table appears to have exactly one
> column, so this will never happen, and setting minimumWidth
> is pointless. Without this, grabHorizontal = true fits the
> editor to the column, and setting horizontalAlignment is
> also pointless.
>
> If you leave these fields alone and add
>
> table.addControlListener(new ControlAdapter() {
> public void controlResized(ControlEvent e) {
> column.setWidth(table.getClientArea().width);
> }
> });
>
> the gizmo is resizable in x and y, and looks like an editable
> list whatever:
>
> public static void main(String[] args) {
> Display display = new Display();
> final Shell shell = new Shell(display);
> shell.setLayout( new FillLayout());
> final Table table = new Table(shell, SWT.FULL_SELECTION |
> SWT.HIDE_SELECTION);
> table.setLinesVisible(true);
> final TableColumn column = new TableColumn(table, SWT.NONE);
> for (int i = 0; i < 10; i++) {
> TableItem item = new TableItem(table, SWT.NONE);
> item.setText("item " + i);
> }
> final TableEditor editor = new TableEditor(table);
> editor.grabHorizontal = true;
> final int EDITABLECOLUMN = 0;
> table.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> Control oldEditor = editor.getEditor();
> if (oldEditor != null)
> oldEditor.dispose();
> TableItem item = (TableItem) e.item;
> if (item == null)
> return;
> Text newEditor = new Text(table, SWT.NONE);
> newEditor.setText(item.getText(EDITABLECOLUMN));
> newEditor.addModifyListener(new ModifyListener() {
> public void modifyText(ModifyEvent e) {
> Text text = (Text) editor.getEditor();
> editor.getItem().setText(EDITABLECOLUMN,
> text.getText());
> }
> });
> newEditor.selectAll();
> newEditor.setFocus();
> editor.setEditor(newEditor, item, EDITABLECOLUMN);
> }
> });
> table.addControlListener(new ControlAdapter() {
> public void controlResized(ControlEvent e) {
> column.setWidth(table.getClientArea().width);
> }
> });
> shell.setSize(300, 300);
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
>
> Paul Singleton
Re: Single column table possible? [message #443788 is a reply to message #443762] Thu, 30 September 2004 15:21 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Calling getClientArea does not include scrollbars or borders. Calling
getSize gives the outside size of the table.

"Craig Setera" <csetera@spss.com> wrote in message
news:cjgvgc$jsl$1@eclipse.org...
> Paul hit on exactly the implementation I came up with. The "concept" that
> I pulled from Grant's example was setting the width of the column directly
> rather than using TableLayout. It seemed that even if I told the
> TableLayout to use all of the space, it never really did. I hadn't
> realized that I wasn't seeing an extra column, but I was seeing the extra
> space the single column wasn't filling.
>
> What is the difference between getClientArea() and getSize()? I used
> getSize() in my case and it seemed to work correctly.
>
> Paul Singleton wrote:
>>
>> I was experimenting with different values for those two, and
>> nothing made any difference, even commenting them out.
>>
>> I think I've figured it out: (at least for win32) you only
>> get an editor wider than the column if there is extra table
>> width to the right of the column. Craig wants a virtual
>> editable List, where the table appears to have exactly one
>> column, so this will never happen, and setting minimumWidth
>> is pointless. Without this, grabHorizontal = true fits the
>> editor to the column, and setting horizontalAlignment is
>> also pointless.
>>
>> If you leave these fields alone and add
>>
>> table.addControlListener(new ControlAdapter() {
>> public void controlResized(ControlEvent e) {
>> column.setWidth(table.getClientArea().width);
>> }
>> });
>>
>> the gizmo is resizable in x and y, and looks like an editable
>> list whatever:
>>
>> public static void main(String[] args) {
>> Display display = new Display();
>> final Shell shell = new Shell(display);
>> shell.setLayout( new FillLayout());
>> final Table table = new Table(shell, SWT.FULL_SELECTION |
>> SWT.HIDE_SELECTION);
>> table.setLinesVisible(true);
>> final TableColumn column = new TableColumn(table, SWT.NONE);
>> for (int i = 0; i < 10; i++) {
>> TableItem item = new TableItem(table, SWT.NONE);
>> item.setText("item " + i);
>> }
>> final TableEditor editor = new TableEditor(table);
>> editor.grabHorizontal = true;
>> final int EDITABLECOLUMN = 0;
>> table.addSelectionListener(new SelectionAdapter() {
>> public void widgetSelected(SelectionEvent e) {
>> Control oldEditor = editor.getEditor();
>> if (oldEditor != null)
>> oldEditor.dispose();
>> TableItem item = (TableItem) e.item;
>> if (item == null)
>> return;
>> Text newEditor = new Text(table, SWT.NONE);
>> newEditor.setText(item.getText(EDITABLECOLUMN));
>> newEditor.addModifyListener(new ModifyListener() {
>> public void modifyText(ModifyEvent e) {
>> Text text = (Text) editor.getEditor();
>> editor.getItem().setText(EDITABLECOLUMN,
>> text.getText());
>> }
>> });
>> newEditor.selectAll();
>> newEditor.setFocus();
>> editor.setEditor(newEditor, item, EDITABLECOLUMN);
>> }
>> });
>> table.addControlListener(new ControlAdapter() {
>> public void controlResized(ControlEvent e) {
>> column.setWidth(table.getClientArea().width);
>> }
>> });
>> shell.setSize(300, 300);
>> shell.open();
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch())
>> display.sleep();
>> }
>> display.dispose();
>> }
>>
>> Paul Singleton
Previous Topic:how to download files with Browser widget
Next Topic:SWT & .NET - why don't they look the same?
Goto Forum:
  


Current Time: Wed Apr 24 16:53:17 GMT 2024

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

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

Back to the top