Home Answers Viewqa Java-Beginners Canvas won't draw on composite (SWT)

 
 


Michael
Canvas won't draw on composite (SWT)
0 Answer(s)      9 months ago
Posted in : Java Beginners

I can't get a canvas to draw on a composite with SWT. I've made the composite on a shell and given it a layout but the canvas won't draw the image. Please help me and bare with me because I'm new to java. The relevant code is below.

public static void main(String[] args) {

    final Display display = new Display();
    final Image img = new Image(display,"C:\\Users\\Public\\Pictures\\Sample 
                                  Pictures\\Lighthouse.jpg");

    final Shell shell = new Shell(display);
    shell.setText("Canvas in Composite");

    Composite comp = new Composite(shell, SWT.BORDER);
    comp.setBounds(0, 0, 500, 500);
    comp.setLayout(new FillLayout());

    final Canvas can = new Canvas(comp, SWT.NONE);
    can.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.drawImage(img, 0, 0);
        }
    });

    shell.open();

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

    img.dispose();
    display.dispose();
}
View Answers









Related Pages:
Canvas won't draw on composite (SWT)
Canvas won't draw on composite (SWT)  I can't get a canvas to draw on a composite with SWT. I've made the composite on a shell and given it a layout but the canvas won't draw the image. Please help me and bare with me because I'm
Canvas placing problem
Canvas placing problem  how to place a canvas in swt under a toolbar
Draw Calendar in SWT
Draw Calendar in SWT       This section illustrates you how to draw  a calendar in SWT, showing current date. SWT allows to create Calendar by using the java.util.Calendar class
SWT
in the layout.    Draw Calendar in SWT SWT allows... In SWT, we have used the package org.eclipse.draw2D.Graphics to draw the figure... SWT      
Draw String Using Canvas
Draw String Using Canvas       This example is used to draw string on different location which is shown in figure. The given code is used to show, how to draw string at different
Draw Font Using Canvas Example
Draw Font Using Canvas Example       This example is used to draw the different types of font using Canvas class. The following line of code is used to show the different style
Draw Clip Area Using Canvas
Draw Clip Area Using Canvas       This Example is going to draw a clip with SOLID line. In this picture only solid line show the clipping area. To draw a solid line, we have
Draw a Flowchart
canvas. To draw the terminator box, process box decision box in flowchart, we have... Draw a Flowchart       This section illustrates you how to draw a Flowchart to compute
Line Canvas MIDlet Example
;CanvasCrossLine" class created by us extends the Canvas class to draw both... Line Canvas MIDlet Example       In this example, we are going to draw to different lines which cross
J2ME Draw Triangle
J2ME Draw Triangle       As you already aware of the canvas class and it's use in J2ME application, we are using canvas class to draw the triangle on the screen. In this example
Image Icon Using Canvas Example
Image Icon Using Canvas Example     ... location using Canvas class. In this example to create the image we are using following code: And for draw the image we are using following code of lines
Simple Line Canvas Example
and another is Graphics.SOLID. To draw this canvas we are uses the following methods... Simple Line Canvas Example       This is a simple example of drawing lines using canvas class
Rotate Text in Java
;  In this section, you will study how to draw the rotated text in Java using SWT. In SWT, we have used the package org.eclipse.draw2D.Graphics to draw the figure on to the surface. The interface IFigure allows to create
Rectangle Canvas MIDlet Example
that extends to the Canvas class to draw the given types of rectangle. In this figure... Rectangle Canvas MIDlet Example       The example illustrates how to draw the different types
Image Icon Using Canvas Example
Image Icon Using Canvas Example   ... location using Canvas class. In this example to create the image we are using...;Image.createImage("/mancartoon.png"); And for draw
Draw arc in J2ME
Draw arc in J2ME       The given example is going to draw an arc using canvas class of J2ME. You can also set a color for it, as we did in our example. Different methods
SWT_AWT bridge ,jtextfield edit problem - Swing AWT
bridge in my code to embed swing components in to SWT Composite. I am using SWT...); java.awt.Frame frame = SWT_AWT.new_Frame(composite); JApplet applet==new JApplet...(new RowLayout( )); java.awt.Frame frame = SWT_AWT.new_Frame(composite
Create Expand Bar in SWT
Create Expand Bar in SWT       This section illustrates you how to create an Expand Bar. SWT provides... of the Expand bar. The method setControl(composite) sets the control
J2ME Canvas Example
J2ME Canvas Example       A J2ME Game Canvas Example This example illustrates how to create... to draw the circle and rotate the circle continuously. The GameCanvas class has
Create a Sash in SWT
Create a Sash in SWT       In this section, you will study how to create a Sash In SWT...;}   public void create(Composite composite) {  
Draw Grids
Draw Grids       This section illustrates you how to draw grids. To draw the grids, we have...;   Now create a canvas and add it to the frame by the following code
Jigloo SWT/Swing GUI Builder
Jigloo SWT/Swing GUI Builder   ... both Swing and SWT GUI classes. Jigloo creates and manages code for all the parts of Swing or SWT GUIs as well as code to handle events, and shows you
Create Progress Bar in SWT
Create Progress Bar in SWT   ... Bar. SWT allows to create a Progress bar by providing the class ProgressBar... in pixels. The method gc.getFontMetrics returns the font metrics to draw
Draw Line in J2me
and class to draw a line.  Basically in J2ME, Canvas class is used to draw... Draw Line in J2me       In this example we are going to show you how to draw a line using J2ME. Please
Color Composite Example
Color Composite Example     .... Alpha Composite class adds another element to the composting rules i.e....;ColorCompositeExample extends JFrame {   Canvas1 canvas
Composite Pattern
Composite Pattern       Individual objects as well as the composite objects can be represented with the Composite Design Pattern. Composite pattern represents these objects
Is it possible in SWT ?
Is it possible in SWT ?  I want drop down like google search (ie, when we type one letter then the word start with that are displayed). when the drop... do this in SWT ? Thanks
HIBERNATE COMPOSITE ID - Hibernate
HIBERNATE COMPOSITE ID  Hi, I have a database table structure as CREATE TABLE `attendance` ( `sno` int(11) NOT NULL auto_increment... ever time. SO i want to make Emploee ref & date as composite. Is there any body
SWT
Composite Components
Composite Components This section contains a brief description and complete example over Composite Components in JSF2.0 . About Composite Components The composite component is a template which behaves as reusable component
Use Alpha values to draw in Layers
Use Alpha values to draw in Layers   ... values to the draw the specific shape in layers. An alpha object produces the alpha.... The alpha value is the graphics state parameter that is used to composite objects
Adding customitem in canvas in J2ME?
Adding customitem in canvas in J2ME?  In J2ME how should we add... for customitem.The key event handling is allowed in canvas not in form.So i try to use canvas instead of form
SWT in Eclipse - Java Beginners
SWT in Eclipse  hi.. how to call a function in SWT when the shell is about to close... ?? thanks in advance
Define candidate key, alternate key, composite key.
Define candidate key, alternate key, composite key.  Define candidate key, alternate key, composite key
Temperature Converter in SWT
Temperature Converter in SWT   ... Fahrenheit to Celsius. SWT provides the class ApplicationWindow of package... Composite contains the controls. The method converterComposite.setLayout() sets
hibernate annotations with composite primary key
hibernate annotations with composite primary key  I want to know how to use hibernate annotations in case of composite primary key in one table. I... created a composite primary key with all the columns of the table. table
Text Example in J2ME
; In J2ME programming language canvas class is used to paint and draw the diagrams. Using the same canvas class we are going to draw a box around the text... that extends the predefined canvas class to draw the box. In the code we have used
Creating Composite Widgets using GWT
Creating Composite Widgets using GWT       This example describes the Basics for creating composite widgets using GWT. The steps involved in Building the Composite
Create Table in SWT
Create Table in SWT       In this section, you will study how to create a table. SWT provides...;void createContents(Composite composite) {   
Program compiles but won't execute - Java Beginners
Program compiles but won't execute  I have to write a program with a class Employee and then write a driver class to run it. This is what I have so far for the Employee class(it compiles but does not execute); public class
SWT Solaris - Swing AWT
SWT Solaris  Hi, When I am using SWT in my application it works... in SWT which will give the exact behaviour in all platforms. Thanks...://www.roseindia.net/tutorials/swt/ Thanks
Draw Line
Draw Line  sir i want to draw a moving line in j2me.That line should also show arrow in moving direction. How can we do so
Java draw triangle draw method?
Java draw triangle draw method?  hi how would i construct the draw method for an triangle using the 'public void draw (graphics g ) method? im... a rectangle and this works for a rectangle: public void draw(Graphics g
J2ME Draw String
J2ME Draw String      ... have created a a class called GraphicsCanvas class that extends to the Canvas class to draw the string. Given methods are used to set the actual layout
Canvas Layout Container
Canvas Layout Container       Canvas container is one of the commonly used container in flex. It defines a rectangular placeholder where its child components can be placed. Canvas
Co-ordinates MIDlet Example
;  In this example the CoordinatesCanvas class extends the Canvas class  to draw the image and fill color as given below in the figure. The following methods is used to draw the image: image = Image.createImage
Draw Rectangle in J2ME
it to create rectangle and to set the color of canvas and draw line or box.  ... Draw Rectangle in J2ME      ... are used to draw a rectangle using J2ME language: g.setColor (255, 
Creating Composite Widgets using GWT
Creating Composite Widgets using GWT       This example describes the Basics for creating composite widgets using GWT. The steps involved in Building the Composite
Draw different curves with QuadCurve2D
Draw different curves with QuadCurve2D       This section illustrates you how to draw different...;extends JApplet {  Canvas1 canvas; public static void 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.