Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » SWT PaintListener question
SWT PaintListener question [message #251182] Tue, 11 March 2008 03:18 Go to next message
Eclipse UserFriend
Originally posted by: todd_hsieh.yahoo.com

Hi

Please help. I create a CTabFolder when start the program. Then user can
launch a File browser to select a file. When file is selected, I tried to
create an CTabItem that draws something. The result is that I can see the
tab has been created but nothing was draw. However, if I click on the tab,
it draws. Or it can be draw if creating tab right after creating
CTabFolder. The PaintListener seems not called successfully. How to make
it draw whenever the tab is created?

/*
* Called in main
*/
public TabControl(Display display, Shell shell) {
this.shell = shell;
this.display = display;
folder = new CTabFolder(shell, SWT.BORDER);
folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
folder.setSimple(false);
folder.setUnselectedCloseVisible(true);
}


/*
* Called from StartProcess()
*/
public void CreateTab() {
CTabItem item = new CTabItem(folder, SWT.CLOSE);
item.setText("SequenceDiagram ");
Composite comp = new Composite(folder, SWT.NONE);
comp.setLayout(new FillLayout());
item.setControl(comp);

drawingCanvas = new Canvas(comp, SWT.BORDER);
drawingCanvas.addPaintListener(new SDPaintListener());
drawingCanvas.setBackground(display.getSystemColor(SWT.COLOR _WHITE));
drawingCanvas.setFocus();
drawingCanvas.redraw();
folder.addCTabFolder2Listener(new CTabFolder2Adapter() {
public void close(CTabFolderEvent event) {
}
});
}


private class SDPaintListener implements PaintListener {
public void paintControl(PaintEvent e) {

DrawInfo drawInfo = null;
drawInfo = new DrawInfo("DUM",
firstEntity_x, firstEntity_y);
drawEntity(e.gc, e.display, drawInfo); }



/*
* called when file is selected
*/
public void StartProcess(String fileName) {
...
CreateTab();
}
Re: SWT PaintListener question [message #251186 is a reply to message #251182] Tue, 11 March 2008 04:02 Go to previous message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
After you've created the tab and its associated control, call:

folder.setSelection(item);

Matthew

Todd wrote:
> Hi
> Please help. I create a CTabFolder when start the program. Then user can
> launch a File browser to select a file. When file is selected, I tried
> to create an CTabItem that draws something. The result is that I can see
> the tab has been created but nothing was draw. However, if I click on
> the tab, it draws. Or it can be draw if creating tab right after
> creating CTabFolder. The PaintListener seems not called successfully.
> How to make it draw whenever the tab is created?
> /*
> * Called in main
> */
> public TabControl(Display display, Shell shell) {
> this.shell = shell;
> this.display = display;
> folder = new CTabFolder(shell, SWT.BORDER);
> folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
> false));
> folder.setSimple(false);
> folder.setUnselectedCloseVisible(true);
> }
>
>
> /*
> * Called from StartProcess()
> */
> public void CreateTab() {
> CTabItem item = new CTabItem(folder, SWT.CLOSE);
> item.setText("SequenceDiagram ");
> Composite comp = new Composite(folder, SWT.NONE);
> comp.setLayout(new FillLayout());
> item.setControl(comp);
>
> drawingCanvas = new Canvas(comp, SWT.BORDER);
> drawingCanvas.addPaintListener(new SDPaintListener());
>
> drawingCanvas.setBackground(display.getSystemColor(SWT.COLOR _WHITE));
> drawingCanvas.setFocus();
> drawingCanvas.redraw();
> folder.addCTabFolder2Listener(new CTabFolder2Adapter() {
> public void close(CTabFolderEvent event) {
> }
> });
> }
>
>
> private class SDPaintListener implements PaintListener {
> public void paintControl(PaintEvent e) {
>
> DrawInfo drawInfo = null;
> drawInfo = new DrawInfo("DUM",
> firstEntity_x, firstEntity_y);
> drawEntity(e.gc, e.display, drawInfo); }
>
>
>
> /*
> * called when file is selected
> */
> public void StartProcess(String fileName) {
> ...
> CreateTab();
> }
>
>
>
Previous Topic:General questions
Next Topic:Getting information from other plugins
Goto Forum:
  


Current Time: Sun Jun 30 13:17:16 GMT 2024

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

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

Back to the top