473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Java SWT - Canvas: why delete images ?

Hello,
I have a problem.
I use SWT to make GUI.
In the main window I have drawed some images (canvas, gc on canvas) and pressing a button will appear a new window. When I I move the new window over the main window the images will disappear. Why ?

Sorry for my english :)
I hope that you will understand.

Thank you
Carmine

Ps: if you want i can send an image
Attached Images
File Type: jpg problema.jpg (18.8 KB, 678 views)
Oct 3 '07 #1
19 7294
r035198x
13,262 8TB
Hello,
I have a problem.
I use SWT to make GUI.
In the main window I have drawed some images (canvas, gc on canvas) and pressing a button will appear a new window. When I I move the new window over the main window the images will disappear. Why ?

Sorry for my english :)
I hope that you will understand.

Thank you
Carmine

Ps: if you want i can send an image
Let's see the code.
Oct 3 '07 #2
public class grafica extends javax.swing.JFrame {
Shell shell;
Text text;
//GC gc;
public grafica() throws IOException, Exception {
Menu menuBar, fileMenu, helpMenu;
MenuItem fileMenuHeader, aboutMenuHeader;
MenuItem fileExitItem, aboutAboutItem;

display = new Display();
shell = new Shell(display);
shell.setText("Composer");

menuBar = new Menu(shell, SWT.BAR);
fileMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
fileMenuHeader.setText("&File");
fileMenu = new Menu(shell, SWT.DROP_DOWN);
fileMenuHeader.setMenu(fileMenu);

MenuItem expertItem = new MenuItem(fileMenu, SWT.CASCADE);
expertItem.setText("&Expert");
Menu submenu = new Menu(shell, SWT.DROP_DOWN);
expertItem.setMenu(submenu);
MenuItem expertParseInItem = new MenuItem(submenu, SWT.PUSH);
expertParseInItem.setText("Parse Input\tCTRL+P");
expertParseInItem.setAccelerator(SWT.CTRL + 'P');
MenuItem dialogItem = new MenuItem(submenu, SWT.PUSH);
dialogItem.setText("&Parse Output\tCTRL+O");
dialogItem.setAccelerator(SWT.CTRL + 'O');
MenuItem separator = new MenuItem(fileMenu, SWT.SEPARATOR);

fileExitItem = new MenuItem(fileMenu, SWT.PUSH);
fileExitItem.setText("E&xit\tCTRL+C");
fileExitItem.setAccelerator(SWT.CTRL + 'C');

aboutMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
aboutMenuHeader.setText("Info");
helpMenu = new Menu(shell,SWT.DROP_DOWN);
aboutMenuHeader.setMenu(helpMenu);
aboutAboutItem = new MenuItem(helpMenu, SWT.PUSH);
aboutAboutItem.setText("Info");

fileExitItem.addSelectionListener(new MenuItemListener());
aboutAboutItem.addSelectionListener(new MenuItemListener());
expertParseInItem.addSelectionListener(new MenuItemListener());

Rectangle screen = display.getMonitors()[0].getBounds();

shell.setMenuBar(menuBar);
// Creazione ToolBar
Image image = new Image(display,"img/Parse.jpg");
Image image2 = new Image(display,"img/Help.jpg");
//GC gc = new GC(image);
//GC gc2 = new GC(image2);
//gc.dispose();
//gc2.dispose();
ToolBar toolBar = new ToolBar(shell, SWT.NO);

ToolItem itemParse = new ToolItem(toolBar, SWT.PUSH);
itemParse.setImage(image);
itemParse.setText("Parse In");
ToolItem itemHelp = new ToolItem(toolBar, SWT.PUSH);
itemHelp.setImage(image2);
itemHelp.setText("Help");
//itemHelp.addSelectionListener(new ToolBarButtonListener());


itemParse.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e2) {
System.out.println("E' stato premuto il tasto ParseIn");
RWmidi midi = null;
try {
midi = new RWmidi("midi.mid");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Parser parser = new Parser(midi);
String eventi = parser.getParsingTraccia(1);
Shell dialog = new Shell(shell);
dialog.setText("Dialog");
Text text4 = new Text(dialog, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
text4.setBounds(0,0,800,500);
text4.setEditable(false);
text4.setText(eventi);
dialog.setSize(800, 500);
dialog.open();
}
});



itemHelp.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("E' stato premuto il tasto Help");
MessageBox aboutBox = new MessageBox(shell,SWT.ICON_INFORMATION);
aboutBox.setText("Informazioni");
StringBuffer messaggio = new StringBuffer();
messaggio.append("Composer Midi\n");
messaggio.append("Programma sviluppato da Fedullo Carmine\n");
messaggio.append("\n");
messaggio.append("Per ulteriori informazioni\n");
messaggio.append("carmine82@gmail.com\n");
aboutBox.setMessage(messaggio.toString());
int buttonOK = aboutBox.open();
//shell.pack();
shell.open();
}
});
toolBar.pack();

// Creazione Separatore
Label separatore = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
separatore.setBounds(0,83,1000,20);

// Creazione Cavas
Canvas canvas = new Canvas(shell, SWT.BORDER);
canvas.setSize(950, 500);
canvas.setLocation(20, 120);

Point size = shell.computeSize(-1,-1);
shell.setBounds(0, 0, 0, 0);
//shell.setSize(screen.width,screen.height-30);
shell.setSize(1000,700);
shell.open();
Color black = display.getSystemColor(SWT.COLOR_BLACK);
Color white = display.getSystemColor(SWT.COLOR_WHITE);
//canvas.setBackground(white);
//canvas.setBackgroundMode(2);
gc = new GC(canvas);


//canvas.setBackground(white);

gc.setBackground(white);
gc.setForeground(black);
gc.fillRectangle(0, 0, 1000, 900);

//gc.setLineWidth(2);
// Costruzione Pentagramma
gc.drawLine(30, 50, 930, 50);
//gc.drawLine(30, 60, 930, 60);
//gc.drawLine(30, 70, 930, 70);
//gc.drawLine(30, 80, 930, 80);
//gc.drawLine(30, 90, 930, 90);
costruisciPentagramma(50,0);
costruisciPentagramma(120,0);
costruisciPentagramma(190,0);
costruisciPentagramma(260,0);
costruisciPentagramma(330,0);
costruisciPentagramma(400,0);
gc.dispose();
//canvas.redraw();
// shell.pack();


while(!shell.isDisposed())
if(!display.readAndDispatch())
display.sleep();
display.dispose();

}
/*
class ToolBarButtonListener extends SelectionAdapter {
public void widgetSelected(SelectionEvent event) {
if(event.widget.getData().)
shell.close();
System.exit(0);
}
}
*/

public void costruisciPentagramma(int altezza, int chiave) {
// Chiave di Basso
if(chiave==0) {
Image img = new Image(display, "img/chiavebasso80.jpg");
gc.drawImage(img, 25, altezza-5);
}
gc.drawLine(30, altezza, 30, altezza+40);
gc.drawLine(30, altezza, 930, altezza);
gc.drawLine(30, altezza+10, 930, altezza+10);
gc.drawLine(30, altezza+20, 930, altezza+20);
gc.drawLine(30, altezza+30, 930, altezza+30);
gc.drawLine(30, altezza+40, 930, altezza+40);
gc.drawLine(300, altezza,300 ,altezza+40);
gc.drawLine(510, altezza,510 ,altezza+40);
gc.drawLine(720, altezza,720 ,altezza+40);
gc.drawLine(930, altezza,930 ,altezza+40);

}
public void newWindow(String titolo, String messaggio) {
Shell dialog = new Shell(shell);
dialog.setText("Dialog");
Text text4 = new Text(dialog, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
text4.setBounds(0,0,800,500);
text4.setEditable(false);
text4.setText("ciao provola affumicata");
dialog.setSize(800, 500);
dialog.open();
}
class MenuItemListener extends SelectionAdapter {
public void widgetSelected(SelectionEvent event) {
if (((MenuItem) event.widget).getText().equals("E&xit\tCTRL+C")) {
shell.close();
System.exit(0);
}
if (((MenuItem) event.widget).getText().equals("Info")) {
MessageBox aboutBox = new MessageBox(shell,SWT.ICON_INFORMATION);
aboutBox.setText("Informazioni");
StringBuffer messaggio = new StringBuffer();
messaggio.append("Composer Midi\n");
messaggio.append("Programma sviluppato da Fedullo Carmine\n");
messaggio.append("\n");
messaggio.append("Per ulteriori informazioni\n");
messaggio.append("carmine82@gmail.com\n");
aboutBox.setMessage(messaggio.toString());
int buttonOK = aboutBox.open();
//shell.pack();
shell.open();
System.out.println("premuto help");
}
if (((MenuItem) event.widget).getText().equals("Parse Input\tCTRL+P")) {
RWmidi midi = null;
try {
midi = new RWmidi("midi.mid");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Parser parser = new Parser(midi);
String eventi = parser.getParsingTraccia(1);
Shell dialog = new Shell(shell);
dialog.setText("Dialog");
Text text4 = new Text(dialog, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
text4.setBounds(0,0,800,500);
text4.setEditable(false);
text4.setText(eventi);
dialog.setSize(800, 500);
dialog.open();


}
}
}
private GC gc;
private Display display;
}
Oct 3 '07 #3
This occur even when I move another application window over images as you can see by attached picture.
Attached Images
File Type: jpg problema2.jpg (17.9 KB, 549 views)
Oct 3 '07 #4
JosAH
11,448 Expert 8TB
Either use Swing components or SWT components but not both.

kind regards,

Jos
Oct 3 '07 #5
Either use Swing components or SWT components but not both.

kind regards,

Jos
Dear Jos,
I use only SWT in my code.
Where do you see Swing components ?

Thank you,
Carmine
Oct 3 '07 #6
r035198x
13,262 8TB
Dear Jos,
I use only SWT in my code.
Where do you see Swing components ?

Thank you,
Carmine
What does your class extend?
Oct 3 '07 #7
What does your class extend?

mmm ... sorry I am distract :)

and now I must change all code ?
What is the class to extend about SWT ?

I have deleted "extends javax.swing.JFrame" but it is the same about my problem.
Oct 3 '07 #8
r035198x
13,262 8TB
mmm ... sorry I am distract :)

and now I must change all code ?
What is the class to extend about SWT ?

I have deleted "extends javax.swing.JFrame" but it is the same about my problem.
If you want to use AWT then you use Frame instead of JFrame. If you want to use swing then there's lots of things you want to change in your code. You have read something about AWT vs swing haven't you? You have to use the right tool for the right job.
Oct 3 '07 #9
JosAH
11,448 Expert 8TB
If you want to use AWT then you use Frame instead of JFrame. If you want to use swing then there's lots of things you want to change in your code. You have read something about AWT vs swing haven't you? You have to use the right tool for the right job.
It's a bit more complicated here: the OP wants to use SWT, not AWT; I guess
that some of the imports in the source are incorrect; we can't know because we
haven't seen the imports.

kind regards,

Jos
Oct 3 '07 #10
It's a bit more complicated here: the OP wants to use SWT, not AWT; I guess
that some of the imports in the source are incorrect; we can't know because we
haven't seen the imports.

kind regards,

Jos
Sorry if my question is stupid but I am learning SWT only since yesterday.

My imports are:

import java.io.IOException;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;

I have deleted "extends java.awt.Frame" and I have the same previous fault.

Thank you
Carmine
Oct 3 '07 #11
r035198x
13,262 8TB
It's a bit more complicated here: the OP wants to use SWT, not AWT; I guess
that some of the imports in the source are incorrect; we can't know because we
haven't seen the imports.

kind regards,

Jos
Yep, I realized after posting that it's SWT not AWT that they want.
Oct 3 '07 #12
Dear Sirs,
please can you confirm that I am using only SWT ?
Oct 4 '07 #13
r035198x
13,262 8TB
Dear Sirs,
please can you confirm that I am using only SWT ?
javax.swing.JFrame is swing.
Oct 4 '07 #14
JosAH
11,448 Expert 8TB
javax.swing.JFrame is swing.
Have a look at reply #11; all the Swing stuff is gone now; I gotta run now; I'll look
at this thread later.

kind regards,

Jos
Oct 4 '07 #15
javax.swing.JFrame is swing.
Now this is the code and I think that there is only SWT

import java.io.IOException;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;

public class grafica {
Shell shell;
Text text;
//GC gc;
public grafica() throws IOException, Exception {
Menu menuBar, fileMenu, helpMenu;
MenuItem fileMenuHeader, aboutMenuHeader;
MenuItem fileExitItem, aboutAboutItem;

display = new Display();
shell = new Shell(display);
shell.setText("Composer");

menuBar = new Menu(shell, SWT.BAR);
fileMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
fileMenuHeader.setText("&File");
fileMenu = new Menu(shell, SWT.DROP_DOWN);
fileMenuHeader.setMenu(fileMenu);

MenuItem expertItem = new MenuItem(fileMenu, SWT.CASCADE);
expertItem.setText("&Expert");
Menu submenu = new Menu(shell, SWT.DROP_DOWN);
expertItem.setMenu(submenu);
MenuItem expertParseInItem = new MenuItem(submenu, SWT.PUSH);
expertParseInItem.setText("Parse Input\tCTRL+P");
expertParseInItem.setAccelerator(SWT.CTRL + 'P');
MenuItem dialogItem = new MenuItem(submenu, SWT.PUSH);
dialogItem.setText("&Parse Output\tCTRL+O");
dialogItem.setAccelerator(SWT.CTRL + 'O');
MenuItem separator = new MenuItem(fileMenu, SWT.SEPARATOR);

fileExitItem = new MenuItem(fileMenu, SWT.PUSH);
fileExitItem.setText("E&xit\tCTRL+C");
fileExitItem.setAccelerator(SWT.CTRL + 'C');

aboutMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
aboutMenuHeader.setText("Info");
helpMenu = new Menu(shell,SWT.DROP_DOWN);
aboutMenuHeader.setMenu(helpMenu);
aboutAboutItem = new MenuItem(helpMenu, SWT.PUSH);
aboutAboutItem.setText("Info");

fileExitItem.addSelectionListener(new MenuItemListener());
aboutAboutItem.addSelectionListener(new MenuItemListener());
expertParseInItem.addSelectionListener(new MenuItemListener());
/*
Text text1 = new Text(shell, SWT.BORDER);
text1.setText("Scrivi");
text1.setBounds(50,100,300,20);
text1.setTextLimit(30);
Text text2 = new Text(shell, SWT.NONE);
text2.setEchoChar('*');
text2.setBounds(50,150,300,20);
text2.setText("Password");
Text text3 = new Text(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
text3.setBounds(50,190,300,100);
text3.setEditable(false);
text3.setText("Qui non puoi scrivere");

*/
Rectangle screen = display.getMonitors()[0].getBounds();

shell.setMenuBar(menuBar);
// Creazione ToolBar
Image image = new Image(display,"img/Parse.jpg");
Image image2 = new Image(display,"img/Help.jpg");
//GC gc = new GC(image);
//GC gc2 = new GC(image2);
//gc.dispose();
//gc2.dispose();
ToolBar toolBar = new ToolBar(shell, SWT.NO);

ToolItem itemParse = new ToolItem(toolBar, SWT.PUSH);
itemParse.setImage(image);
itemParse.setText("Parse In");
ToolItem itemHelp = new ToolItem(toolBar, SWT.PUSH);
itemHelp.setImage(image2);
itemHelp.setText("Help");
//itemHelp.addSelectionListener(new ToolBarButtonListener());

itemParse.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e2) {
System.out.println("E' stato premuto il tasto ParseIn");
RWmidi midi = null;
try {
midi = new RWmidi("midi.mid");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Parser parser = new Parser(midi);
String eventi = parser.getParsingTraccia(1);
Shell dialog = new Shell(shell);
dialog.setText("Dialog");
Text text4 = new Text(dialog, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
text4.setBounds(0,0,800,500);
text4.setEditable(false);
text4.setText(eventi);
dialog.setSize(800, 500);
dialog.open();
}
});

itemHelp.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("E' stato premuto il tasto Help");
MessageBox aboutBox = new MessageBox(shell,SWT.ICON_INFORMATION);
aboutBox.setText("Informazioni");
StringBuffer messaggio = new StringBuffer();
messaggio.append("Composer Midi\n");
messaggio.append("Programma sviluppato da Fedullo Carmine\n");
messaggio.append("\n");
messaggio.append("Per ulteriori informazioni\n");
messaggio.append("carmine82@gmail.com\n");
aboutBox.setMessage(messaggio.toString());
int buttonOK = aboutBox.open();
//shell.pack();
shell.open();
}
});
toolBar.pack();

// Creazione Separatore
Label separatore = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
separatore.setBounds(0,83,1000,20);

// Creazione Cavas
Canvas canvas = new Canvas(shell, SWT.BORDER);
canvas.setSize(950, 500);
canvas.setLocation(20, 120);

Point size = shell.computeSize(-1,-1);
shell.setBounds(0, 0, 0, 0);
//shell.setSize(screen.width,screen.height-30);
shell.setSize(1000,700);
shell.open();
Color black = display.getSystemColor(SWT.COLOR_BLACK);
Color white = display.getSystemColor(SWT.COLOR_WHITE);
//canvas.setBackground(white);
//canvas.setBackgroundMode(2);
gc = new GC(canvas);


//canvas.setBackground(white);

gc.setBackground(white);
gc.setForeground(black);
gc.fillRectangle(0, 0, 1000, 900);

//gc.setLineWidth(2);
// Costruzione Pentagramma
gc.drawLine(30, 50, 930, 50);
//gc.drawLine(30, 60, 930, 60);
//gc.drawLine(30, 70, 930, 70);
//gc.drawLine(30, 80, 930, 80);
//gc.drawLine(30, 90, 930, 90);
costruisciPentagramma(50,0);
costruisciPentagramma(120,0);
costruisciPentagramma(190,0);
costruisciPentagramma(260,0);
costruisciPentagramma(330,0);
costruisciPentagramma(400,0);
gc.dispose();
//canvas.redraw();
// shell.pack();


while(!shell.isDisposed())
if(!display.readAndDispatch())
display.sleep();
display.dispose();

}
/*
class ToolBarButtonListener extends SelectionAdapter {
public void widgetSelected(SelectionEvent event) {
if(event.widget.getData().)
shell.close();
System.exit(0);
}
}
*/

public void costruisciPentagramma(int altezza, int chiave) {
// Chiave di Basso
if(chiave==0) {
Image img = new Image(display, "img/chiavebasso80.jpg");
gc.drawImage(img, 25, altezza-5);
}
gc.drawLine(30, altezza, 30, altezza+40);
gc.drawLine(30, altezza, 930, altezza);
gc.drawLine(30, altezza+10, 930, altezza+10);
gc.drawLine(30, altezza+20, 930, altezza+20);
gc.drawLine(30, altezza+30, 930, altezza+30);
gc.drawLine(30, altezza+40, 930, altezza+40);
gc.drawLine(300, altezza,300 ,altezza+40);
gc.drawLine(510, altezza,510 ,altezza+40);
gc.drawLine(720, altezza,720 ,altezza+40);
gc.drawLine(930, altezza,930 ,altezza+40);

}
public void newWindow(String titolo, String messaggio) {
Shell dialog = new Shell(shell);
dialog.setText("Dialog");
Text text4 = new Text(dialog, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
text4.setBounds(0,0,800,500);
text4.setEditable(false);
text4.setText("ciao provola affumicata");
dialog.setSize(800, 500);
dialog.open();
}
class MenuItemListener extends SelectionAdapter {
public void widgetSelected(SelectionEvent event) {
if (((MenuItem) event.widget).getText().equals("E&xit\tCTRL+C")) {
shell.close();
System.exit(0);
}
if (((MenuItem) event.widget).getText().equals("Info")) {
MessageBox aboutBox = new MessageBox(shell,SWT.ICON_INFORMATION);
aboutBox.setText("Informazioni");
StringBuffer messaggio = new StringBuffer();
messaggio.append("Composer Midi\n");
messaggio.append("Programma sviluppato da Fedullo Carmine\n");
messaggio.append("\n");
messaggio.append("Per ulteriori informazioni\n");
messaggio.append("carmine82@gmail.com\n");
aboutBox.setMessage(messaggio.toString());
int buttonOK = aboutBox.open();
//shell.pack();
shell.open();
System.out.println("premuto help");
}
if (((MenuItem) event.widget).getText().equals("Parse Input\tCTRL+P")) {
RWmidi midi = null;
try {
midi = new RWmidi("midi.mid");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Parser parser = new Parser(midi);
String eventi = parser.getParsingTraccia(1);
Shell dialog = new Shell(shell);
dialog.setText("Dialog");
Text text4 = new Text(dialog, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
text4.setBounds(0,0,800,500);
text4.setEditable(false);
text4.setText(eventi);
dialog.setSize(800, 500);
dialog.open();
}
}
}
private GC gc;
private Display display;
}
Oct 4 '07 #16
r035198x
13,262 8TB
1.) Please use code tags everytime for posting code.
2.) Shouldn't your class be extending Frame? What happens when you try it with SWT only?
Oct 4 '07 #17
1.) Please use code tags everytime for posting code.
2.) Shouldn't your class be extending Frame? What happens when you try it with SWT only?
1) Ok, sorry...I will use Code tag in the future
2) No, I don't extend Frame Class and when I run the program it work normally but with the same problem.

Early I write this program with swing and after I changed to SWT for this reason I forgot to delete the "extending ....." text.
But all code is only with SWT as you can see.
I have read various manual and tutorial about SWT, and it is not necessary to extend any class. You can use SWT widgets only importing the right packages.
This is Hello World Exemple Code:

Expand|Select|Wrap|Line Numbers
  1. 1 import org.eclipse.swt.*;
  2. 2 import org.eclipse.swt.graphics.*;
  3. 3 import org.eclipse.swt.widgets.*;
  4.  
  5. 4 public class HelloWorld {
  6. 5 public static void main(String[] args){
  7. 6 Display display = new Display();
  8. 7 Shell shell = new Shell(display);
  9. 8 shell.setText("Hello World");
  10. 9 shell.setSize(200,100);
  11. 10 shell.open ();
  12. 11 while (!shell.isDisposed()) {
  13. 12 if (!display.readAndDispatch())
  14. 13 display.sleep ();
  15. 14 }
  16. 15 display.dispose ();
  17. 16 }
  18. 17 }
Thank you
Carmine
Oct 4 '07 #18
JosAH
11,448 Expert 8TB
Dear Sirs,
please can you confirm that I am using only SWT ?
Yep, you're not using any Swing components at all. I had a look at your code
but my SWT knowledge is minimal. I suggest that you strip your application as
much as possible (eg. leave out the Toolbar and the Menubar etc. etc.) until
you end up with a barebones application that either works fine (i.e. it redraws
that image properly) or it still exhibits the same error when the image needs
to be redrawn.

Now it's too much code to plough through.

kind regards,

Jos
Oct 4 '07 #19
valce
1
I know this thread is oooold but it was the first thread I found on Google when I had the same issue. The OP (and myself) were using the wrong way to draw on a canvas. In order to have stuff on the canvas stick around after a repaint, you should add draw functions to the a paintlistener on the canvas, e.g:

canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
GC gc = new GC(c);
drawStuff(gc);
gc.dispose();
}
});

Hopefully the next person who runs into this error and stumbles here will find it useful :)

-C
Feb 22 '10 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Martin | last post by:
Hi All, I am a relative newbie to Java / Applets, but am despirately after some help ! I have got the following code, which is basically a listing with button items along the sides, allowing...
3
by: Matthias | last post by:
Hello, I have a Canvas-Widget and will use as a "array of pixel". At Positon x,y I print a rectangle with a special color. I give the rectangle no objectname. Then I will ask the...
1
by: Mudcat | last post by:
I have an image that displays on a canvas that works unless I put the same code in a class. I can't figure that out. Here's what works: def uts5100(self): self.screen = Toplevel( self.master )...
2
by: billy | last post by:
I'm working on a sort of paint program that has the usual canvas pane in the middle of the main form. I'm working on that class and have a couple quick questions.. actually more like I'm looking...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
26
by: Jon Davis | last post by:
OK, why is Canvas not IDisposable, and how do I get rid of all the Windows handles? I'm doing a performance test of looping through a dynamic XAML-to-JPEG conversion. It gets to about 500...
1
by: dishal | last post by:
Can anyone help me please? How do I convert these codes to launch from a JFrame instead of a Java Applet? A simple program where the user can sketch curves and shapes in a variety of...
6
by: Nebulism | last post by:
I have been attempting to utilize a draw command script that loads a canvas, and through certain mouse events, draws rectangles. The original code is from...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.