Swing component for awt.canvas

Hi,
Can anyone tell me the equivalent SWING component for awt CANVAS. I need it because i need to display only Images (nothing else) on it. If anyone can tell how I can do it.

JPanel is the Swing-equivalent of java.awt.Canvas, but if you are just displaying images, you can use the JLabel class, which supports use of images as icons (see also ImageIcon class).
Mitch Goldstein
Author, Hardcore JFC (Cambridge Univ Press)
[email protected]

Similar Messages

  • New Swing Component for Swing Palette in NetBeans

    Hi guys,
    I want to write a new Swing component (Bean) for drawing vertical and horizontal lines to use with netBeans GUI designer.
    Could anyone direct me to a tutorial
    thanks in advance

    JTextcomponent.

  • Swing Component for viewing huge text file

    i need to view (only view not edit) a huge text file (3 mb)
    jtextarea is for small files i need somthing else

    What error are you getting?
    I was able to bring in a 7MB text file into a JTextArea without problems. It took a while (about 15 seconds), but it still loaded.

  • AWT Canvas vs. Swing "glass pane"

    Hello again world.
    The book I've been reading led me down the Swing path but I thought I would go back and take a closer look at the AWT package.
    Is an AWT Canvas analogous to a Swing JRootPane's glass pane?
    Thank you one and all.
    Ciao for now.

    No, not really.
    1) A Canvas is specifically for drawing. There's really no other purpose for it to exist. It's not a container, like Panel. Although, you can use AWT Panel in place of a Canvas, there'd be nothing wrong with that.
    A glasspane has a purpose in a JFrame or other top-level Swing container. It's there to be shown, but often transparently, on top of all other components in that top-level container. You can make the glasspane be any class, yes, but generally it's going to be a JPanel or subclass, and you could paint on it if you override the paintComponent method, or add mouse listeners to intercept mouse events (when it's visible).
    That you can draw on a Canvas or a glasspane component is irrelevant. One can can subclass JButton or JTree or AWT List or any other AWT or Swing component and override the paint or paintComponent method and do custom painting on it. The ability to paint on components is universal. But you wouldn't use a JButton or AWT Button for a glasspane.
    2) You don't want to use Canvas as a glass pane (or any AWT component) if you want the pane to be transparent. AWT components cannot be transparent, so if the component is visible, it'll block out anything under it. It's the whole issue of AWT's heavyweight components vs Swing's lightweight components.

  • Support for Multilingual Numeral Input in JTextField swing component

    When the User Locale is changed from the regional & language options in the control panel and the standard digits are customized to a non Latin character set, all the windows applications adhere to the changes made. HTML also respects the changes in effect and displays any numeric values using the new character set, which are the national digits for many Eastern Locales such as Chinese, Arabic(Saudi Arabia), Urdu and many more. The JTextField swing component given by java, however, does not show any support to the new settings. Any numeric input is displayed in the Latin character set even when the input locale of the system is also changed respectively. Any text input for this case is correctly displayed in the desired literals and appropriate glyphs. However, unlike the AWT components, numeral input and display is not catered as per the user/developer's requirements. This behavior was first noticed in 2007, as far as i have found out, and was reported once again on the same thread in 2010. The thread is given below as a reference. No action or response has been taken. Kindly look into this matter and please let me know if this bug has been reported before and if there is any intent of providing a fix for it.
    Reference: http://www.coderanch.com/t/344075/GUI/java/Multilingual-support-JTextField
    Regards,
    Aitzaz Ahmad
    Software Engineer
    SENSYS

    I too had an itch to reply with something like this
    This is a sign of work well done!
    The WD has so strong UI abstraction, that hides client-server nature applications almost completely. If you search forum, you will even find posts where developers try to upgrade value of ProgressMeter in <b>for</b> loop )
    VS

  • When, where, and how is a GUI event created for a Swing component?

    Somebody please help me with this issue !
    Heavy weight (AWT) components such as JFrame, JDialog, JApplet, and JWindow have
    native peers. As I understand, the senario of event creation for such heavy components
    is something like follows:
    1. A mouse click happens in a heavy component.
    2. The native platform (i.e. the OS) captures the mouse click event and
    store it as a native event somewhere in the system.
    3. java.awt.EventDispatchThread gets this message and translates the native message
    into an AWTEvent. When creating the AWTEvent, AWT actually looks up a hashtable
    for the reference to the heavy component from the reference to the native window.
    The hashtable stores all the pairs of heavy components and their native peers ever
    created during the session. Now the AWTEvent includes a reference to the "source"
    component that generates the event.
    4. java.awt.EventDispatchThread dispatches the AWTEvent to the heavy component
    for furture processing.
    As for light weight (Swing) components such as JButtion, no native peers are attached.
    So, there is no mapping from native peers to light weight components.
    After a mouse click happens over a JButton, how, when, and where is the corresponding
    event created and finnally routed to JButton. Could somebody give a sketch of the
    senario? Thanks a lot.

    Basically for Swing components, it would have to figure out based on the size and location of the components which one the click happens in. One could simply know that this panel is so big and it has such and such components in it which are however big and located at whatever point. It's a matter of digging down through components to find the lowest (or would it be highest) one.

  • Changing custom AWT component to Swing component

    I created my own AWT component. I'd like to change it to Swing component.
    Does anyone know how to change or create a custom Swing component?
    Please also provide some framework to develop a custom Swing component.

    First try to know the difference between SWING & AWT. You can either adopt to SWING or AWT but be specific of what you want to do !
    If you like to migrate from AWT to SWING ,then make the necessary changes in your coding.(ie, re frame things like , Frame to JFrame , Button to JButton ,JTextField to JTextField etc..)
    For creating custom components ,say a component called MyLabel and you should design a class which extends JLabel and do whatever you like...
    eg import javax.swing.*;
    public class MyLabel extends JLabel
      MyLabel(String title)
         this.setTitle(title);
         this.setBackground(Color.white);
         this.setForeground(Color.blue);
    }For more details go to java tutorials.

  • Component in awt or swing recieving a primitive?

    Hi,
    I am trying to make an application, and looking in the api i couldn?t find any component either in swing or in awt which can work with a primitive data type.
    I would be grateful if someone could tell me if there is a component class whicha i could have skipped that can work with primitives, or otherwise if exists a way to extend a component class modify it so it can work with primitives
    thanks in advance...

    What is your actual goal?
    AWT/Swing is about presentation, which rarely concerns itself with primitives. Make use of the MVC (Model, View, Controller) pattern to separate concerns.

  • New: awt is covering my swing component...

    i am using both awt and swing component on the same page. They are a List and a JComboBox.
    while the JcomboBox is placed above the List. it works fine but when i click on the JComboBox, the pull down menu is covered by the awt List. I know that using JList can solve the problem, but i'm new to swing and i just want to make the smallest change to my code.
    can i use layeredpane to help?

    here is a link to the Swing tutorial that mentions this problem:
    http://java.sun.com/docs/books/tutorial/uiswing/start/swingIntro.html#awt
    The Swing tutorial also has a section on converting from AWT to Swing. You should look at that.
    Here is another article from the Swing Connection titled "Mixing Heavy and Light Components"
    http://java.sun.com/products/jfc/tsc/articles/mixing/index.html
    Like the previous post says, you are better off not to mix the two.

  • Painting a Component on a Canvas

    Hello communtiy :)
    I'm creating a program to view images on an old laptop remade as a digital photo frame running Ubuntu. Seeing as I'm dealing with Linux I want the program to use AWT rather than Swing. I use a java.awt.Canvas to display the image, which works fine, but now I want to add a description to each image. I thought I'd do this by adding the description text to a TextArea and then draw the TextArea somewhere on the Canvas, so as to get the line wrap for free. This is where I'm stuck.
    So, I want to paint a java.awt.TextArea on to a java.awt.Canvas but I can't get the TextArea to show. The dummy code below shows only the text drawn by g.drawString(String, int int), not the one from textArea.paint(Graphics). What am I doing wrong?
    Frame frame = new Frame();
    frame.add(new java.awt.Canvas(){
        public void paint(Graphics g){
             g.drawString("g.drawString", 20, 20);
              java.awt.TextArea textArea = new java.awt.TextArea("TextArea");
              textArea.paint(g);
    frame.pack();
    frame.setVisible(true);Kind Regards

    The old AWT classes work through peers, where there is a heavyweight OS component (like a frame) underlying the AWT component. The problem with this, as you are finding, is that it is extremely limiting. In almost all cases, you can't change how it looks (overridding paint does nothing) or override its default event handling. And calling paint on an AWT class with an Image graphics object paints nothing, so you either have to replicate how your AWT class paints it thru code somehow, or not use AWT.

  • Swing component's margin in a frame

    Hello all,
    When you set the bounds of a Swing component in a frame, it will automatically apply those bounds to the VISIBLE part of the frame, so that, a Y value of 0, for example, will not be at the very top of the frame, but right underneath the title bar of the frame. If you give a regular AWT a value of 0 to it's Y coordinate, part (or all) of it will be covered by the title bar of the frame. This does not happen with Swing components, which automatically add the height of the title bar to the value you give to their Y coordinate.
    Now, what I want to know is, how can I retrieve the value of that "automatic margin"?. How can I know the number of pixels that the Swing component is being slided down, in order to save the title bar of the frame? This value can not be constant, since it will differ from one platform to another, and from one Look 'n Feel to another, but I have not been able to find out the way to get the value that it's being applied in each case.
    As allways, many thanks in advance for your help.

    Don't know if there is any direct way to get this information. But, assuming the border width/height is equal on all four sides you could try something like:
    Dimension frameD = frame.getSize();
    Dimension contentD = frame.getContentPane().getSize();
    int borderWidth = frameD.width - contentD.width;
    int titleHeight = frameD.height - contentD.height - borderWidth;

  • Swing component fires an event to non-GUI code

    Hi all -- this is my first post in forums.sun.com.
    Question to get me started -
    I have a Swing component that fires an ActionEvent. I would like that ActionEvent to trigger code that does not run on the AWT Event Queue thread (some code that will take some time without impacting GUI rendering performance.)
    I know I could put that Event's action command into a synchronized Queue, and have a worker thread checking the queue and taking action when it finds a command there. Likewise, I could flag a volatile boolean as true, and have a worker thread check the flag and take action when true.
    Or (and I suspect this is best), I could create a new SwingWorker thread right in actionPerformed().
    Any opinions on what makes sense?

    pkwooster: Yep. That's what I meant.
    As for the design pattern, Observer was the pattern I was intending to use (and have already implemented). Would anyone argue that another method is more efficient or "correct"?
    My sample project is:
    Business Object -> Main Dialog -> Embedded Dialog
    The Main Dialog contains no business logic - just simple navigation events. The Embedded Dialog contains the real controls and reports any interaction using Swing events, which the Main Dialog picks up.
    I then set up the Observer pattern between the Main Dialog and the Business Object.

  • How to call Ocx in swing Component

    Hi i want to play Flash4 file xxx.swf in swing Component
    JMF Api Supports upto Flash2 only i downloadled Flash4 player which is a ocx file .how can i integrate this ocx in swing Component
    help me please
    regards
    Mahesh.B

    I have used the tool JacoZoom by InfoZoom (http://www.infozoom.de).
    The tool can create JCWs (java callable wrappers) for COM and ActiveX objects.
    If they are visual, you can create and display them within your Java app
    either as AWT or in Swing.
    In general, JacoZoom is the best tool I have found so far, it is my
    favorite.
    Sylvia

  • Multilanguage support for awt components..

    hi all,
    when i tried to use .setFont() method for awt componets like labels and buttons it is displayed as rectangles insted of showing the appropriate characters. actually i tried to set the font to "simsun" (unicode font for chinese). but it works fine for swing components.
    how can we achieve that for awt without changing the font.properties file? or how can we insist to use the font.properties file supplied by us insted of default font.property file for that language?
    can we run the application by putting our font.properties file which is meant to be used for only our application, in the current working folder insted of putting in javahome\jre\lib path?
    thanks in advance..
    regards
    sojan

    Hi Sojan,
    first up, forget the notion of even tinkering with the font.properties file if you can. It's an old, outdated method of setting up the fonts that Sun doesn't even support any more. Use setFont() where you can, and die trying in the process! ;-)
    One thing I would check is which font each AWT component currently thinks it has. It's easy enough to set the font system wide with Swing components, but I'm not sure if that capability extends to AWT components (I've certainly had trouble with it in various places in the past). While you've set up the Chinese font correctly, your AWT components might still be stuck with the Java default (Helvetica, or whatever it is, which is incapable of displaying Chinese), and hence displaying the rectangles because they don't know how to handle the foreign characters. You might need to set SimSun as the font for each of your AWT components individually at a worst-case scenario.
    Hope that helps,
    Martin Hughes

  • File Chooser Component for JavaFX not available?

    Is there a way to have a “File Chooser Component” for JavaFX Applications?
    Netbeans IDE offers a “Palette Swing Windows” Components, displays such item, but I am unable to put it into my FX Script.
    Any workaround? or miss I a anything?
    I want to pickup any sourcefile: "{__DIR__}sound/{soundName}" from local disc and run it on a Mediaplayer

    import javax.swing.filechooser.FileFilter;
    * @author Pawel
    public class OpenFileFilter extends FileFilter {
        override public function getDescription() : String {
            return "all movies";
        override public function accept(f: java.io.File) : Boolean {
            return f.isDirectory()
                or f.getName().endsWith(".avi")
                or f.getName().endsWith(".mov")
                or f.getName().endsWith(".flv");
    import java.awt.SystemTray;
    import java.awt.TrayIcon;
    import java.awt.Toolkit;
    import java.awt.PopupMenu;
    import java.awt.MenuItem;
    import java.awt.AWTException;
    import java.lang.System;
    var stage : Stage = Stage {
        title: "JavaWars"
        width: 800
        height: 600
        scene: scene,
        style: StageStyle.TRANSPARENT,
        extensions: [
            AppletStageExtension {
                shouldDragStart: function(e): Boolean {
                    return inBrowser and e.primaryButtonDown and header.hover;
                onDragStarted: function() {
                    inBrowser = false;
                    addTray();
                onAppletRestored: function() {
                    inBrowser = true;
                    removeTray();
                useDefaultClose: true
    var trayIcon : TrayIcon;
    function addTray() : Void{
        if(SystemTray.isSupported()) {
            var tray : SystemTray  = SystemTray.getSystemTray();
            var image : java.awt.Image = Toolkit.getDefaultToolkit().getImage("{__DIR__}resources/images/trayicon.png");
            var popup : PopupMenu = new PopupMenu();
            var item : MenuItem = new MenuItem("Zako&#324;cz");
            item.addActionListener(ActionListener{
                override public function actionPerformed(e : ActionEvent): Void {
                    var tray : SystemTray  = SystemTray.getSystemTray();
                    tray.remove(trayIcon);
                    stage.close();
            popup.add(item);
            trayIcon = new TrayIcon(image, "kliknij prawym, aby zamkna&#263; aplikacj&#281;", popup);
            try {
                tray.add(trayIcon);
            } catch (e : AWTException) {
                System.err.println("Can't add to tray");
        } else {
            System.err.println("Tray unavailable");
    function removeTray() : Void{
        if(SystemTray.isSupported()) {
            var tray : SystemTray  = SystemTray.getSystemTray();
            try {
                tray.remove(trayIcon);
            } catch (e : AWTException) {
                System.err.println("Can't remove tryicon");
    }

Maybe you are looking for