Home » Newcomers » Newcomers » Draw custom text on Table
Draw custom text on Table [message #264289] |
Mon, 15 September 2008 06:22  |
Eclipse User |
|
|
|
Hello,
is it possible to draw custom text on the table?
I have Table and TableViewer and if there is not data to show, I would
like to display text with such message. I'd like the message to be in
first row, but go throw the more columns or to be in a special place (eg.
in the middle of control).
Agata
|
|
| | | | | |
Re: Draw custom text on Table [message #264552 is a reply to message #264354] |
Fri, 19 September 2008 14:26   |
Eclipse User |
|
|
|
Putting a Label on the Table should work, snippet:
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
shell.setLayout(new FillLayout());
Table table = new Table(shell, SWT.NONE);
table.setLinesVisible(true);
table.setHeaderVisible(true);
shell.open();
Label label = new Label(table, SWT.CENTER);
label.setBackground(table.getBackground());
label.setBounds (5, table.getHeaderHeight(), table.getSize().x - 2 * 5,
table.getItemHeight());
label.setText("no items here");
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
Grant
"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:gannqe$qk9$1@build.eclipse.org...
> Hi Agata,
>
> Ok. Looks like SWT-Table doesn't support SWT-Paint :-( The only trick I
> now see is that you are setting a background image which has the draw
> back that it is rendered behind the Grid-Lines (you could turn them of
> of course).
>
> I've CC'ed the swt-newsgroup maybe some of the others has a better idea.
>
> Tom
>
> Agata Vackova schrieb:
> > I tried to use paint listener (
> > table.addPaintListener(new PaintListener(){
> > public void paintControl(PaintEvent e) {
> > e.gc.drawText("No data", 100, 100);
> > }
> > });
> > ), but it doesn't work: method paintControl is not called at all.
> >
> > Agata
> >
> > Tom Schindl wrote:
> >
> >> Owner Draw doesn't help here I guess because if there are no rows
> >> there's no owner draw because it is bound to Table/TreeItem but a
simple
> >> SWT.Paint-Listener should do the trick.
> >
> >> Tom
> >
> >> Eric Rizzo schrieb:
> >>> Agata Vackova wrote:
> >>>> Hello,
> >>>> is it possible to draw custom text on the table?
> >>>> I have Table and TableViewer and if there is not data to show, I
> >>>> would like to display text with such message. I'd like the message to
> >>>> be in first row, but go throw the more columns or to be in a special
> >>>> place (eg. in the middle of control).
> >>>
> >>> You can probably use the Owner Draw feature to do this. See some
> >>> examples on the Snippets page:
> >>> http://wiki.eclipse.org/index.php/JFaceSnippets
> >>>
> >>> Hope this helps,
> >>> Eric
> >
> >
> >
> >
>
>
> --
> B e s t S o l u t i o n . at
> ------------------------------------------------------------ --------
> Tom Schindl JFace-Committer
> ------------------------------------------------------------ --------
|
|
|
Re: Draw custom text on Table [message #264580 is a reply to message #264552] |
Mon, 22 September 2008 04:38  |
Eclipse User |
|
|
|
Thank you, works fine (except the weight of the label - it it very short,
I'll have probably to hardcore the weight of the label)
Agata
Grant Gayed wrote:
> Putting a Label on the Table should work, snippet:
> public static void main(String[] args) {
> final Display display = new Display();
> final Shell shell = new Shell(display);
> shell.setBounds(10,10,200,200);
> shell.setLayout(new FillLayout());
> Table table = new Table(shell, SWT.NONE);
> table.setLinesVisible(true);
> table.setHeaderVisible(true);
> shell.open();
> Label label = new Label(table, SWT.CENTER);
> label.setBackground(table.getBackground());
> label.setBounds (5, table.getHeaderHeight(), table.getSize().x - 2 * 5,
> table.getItemHeight());
> label.setText("no items here");
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) display.sleep();
> }
> display.dispose();
> }
> Grant
> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
> news:gannqe$qk9$1@build.eclipse.org...
>> Hi Agata,
>>
>> Ok. Looks like SWT-Table doesn't support SWT-Paint :-( The only trick I
>> now see is that you are setting a background image which has the draw
>> back that it is rendered behind the Grid-Lines (you could turn them of
>> of course).
>>
>> I've CC'ed the swt-newsgroup maybe some of the others has a better idea.
>>
>> Tom
>>
>> Agata Vackova schrieb:
>> > I tried to use paint listener (
>> > table.addPaintListener(new PaintListener(){
>> > public void paintControl(PaintEvent e) {
>> > e.gc.drawText("No data", 100, 100);
>> > }
>> > });
>> > ), but it doesn't work: method paintControl is not called at all.
>> >
>> > Agata
>> >
>> > Tom Schindl wrote:
>> >
>> >> Owner Draw doesn't help here I guess because if there are no rows
>> >> there's no owner draw because it is bound to Table/TreeItem but a
> simple
>> >> SWT.Paint-Listener should do the trick.
>> >
>> >> Tom
>> >
>> >> Eric Rizzo schrieb:
>> >>> Agata Vackova wrote:
>> >>>> Hello,
>> >>>> is it possible to draw custom text on the table?
>> >>>> I have Table and TableViewer and if there is not data to show, I
>> >>>> would like to display text with such message. I'd like the message to
>> >>>> be in first row, but go throw the more columns or to be in a special
>> >>>> place (eg. in the middle of control).
>> >>>
>> >>> You can probably use the Owner Draw feature to do this. See some
>> >>> examples on the Snippets page:
>> >>> http://wiki.eclipse.org/index.php/JFaceSnippets
>> >>>
>> >>> Hope this helps,
>> >>> Eric
>> >
>> >
>> >
>> >
>>
>>
>> --
>> B e s t S o l u t i o n . at
>> ------------------------------------------------------------ --------
>> Tom Schindl JFace-Committer
>> ------------------------------------------------------------ --------
|
|
|
Goto Forum:
Current Time: Sat May 10 03:32:47 EDT 2025
Powered by FUDForum. Page generated in 0.08661 seconds
|