AWT/Swing gui flickering

I am trying to add the swing JDesktopPane to java.awt.Frame .The JDesktopPane includes
JInternalFrame.The problem is that the GUI is flickering when resized or moved.
I migrated from jre1.4 to jre1.5 and the flickering of the JDesktopPane stops but the
JInternalFrame is still flickering when resized/moved.I am wondering if at this point
this is a AWT/Swing issue.

Never ever mix AWT and Swing!At least not their components. :p ;)

Similar Messages

  • A new AWT/Swing?

    I have a question for the community.
    IMHO, and I am not alone, AWT/Swing have major flaws that really ought to be fixed. Probably, because the APIs themselves are seriously flawed, what is required is a replacement for Swing.
    How would one go about proposing such a thing and getting Sun's support?
    Specific issues:
    1) A set of specific design rules should be codified, which all conforming components, layout managers, UIs, etc., should obey. Along with the rules, there should be automated tests, so that it could be confirmed whether components, layout managers, UIs, etc., work correctly.
    Currently, Swing and 3rd party components often do not work well together, for reasons such as
    a) Highly irrational behavior of layout managers. Currently, none of the AWT/Swing layout managers behave in a reasonable way under all circumstances, with the possible exception of BorderLayout. Also, layout managers use constraints in inconsistent ways, and they are ill-suited to control by GUI builders.
    b) Failure to use minimumSize, preferredSize, and size consistently.
    c) Inconsistent use of UIs. What is the division of responsibility between the UI, layout managers, L&F, and the main class(es)?
    2) Software design rules. For example, there is currently at least one Swing class that alters its behavior depending on which container it is placed in. That violates basic principles of OO development. Perusing the AWT/Swing source code, you will find plenty of objectional coding practices. It seems that the pressure to maintain backwards compatibility has been a real impediment to "doing things right".
    3) Performance. AWT/Swing are notorious for various performance problems, including
    a) Non-linear CPU cost associated with building certain graphical data structures (combo-boxes, for one).
    b) Layout managers that call getMinimumSize or getPreferredSize on child components multiple times. Currently, the layout managers are the CPU bottleneck in many AWT/Swing GUIs.
    c) Some text components are almost unbelievably slow. Try scrolling a lot of text through a JTextArea and you will be disappointed.
    d) The current validation logic is extremely complex, inefficient, and undocumented. I count approximately 15 basic API methods that affect how and when components are repainted. I defy ANYONE to explain how it all works. The typical result is that repaints occur FAR more often than is necessary.
    A lot of optimization is required to fix these problems. That means automating tests, profiling, removing extra repaints, CPU bottlenecks, etc.
    4) Excessive complexity of the APIs. For example, it seems that building practical tables and trees is harder than it should be. The APIs are complex and documentation obscure or lacking in detail. Also, the separation between model and view is often tainted. It shouldn't be necessary to do so much conversion between model and view indices, for example. A basic set of model classes should be shared by all components that use underlying data models. These model classes should support standard functionality such as filtering, sorting, etc.
    5) No portable remote operation. Yes, I am familiar with SAWT (slow and buggy), and the possibility of using X11 remotely when the Java application is run on a *nix platform (slow over a high-latency network such as the Internet and unusable on Windows systems).  There does not seem to be a usable, universal solution.
    Yes, I am familiar with SWT. However, for a variety of reasons, I believe that the AWT approach is superior. SWT is more platform dependent and it has the X11 reverse-object-orientation in which child classes know about their parents. I have done some performance testing, which suggests that
    1) SWT layout managers are faster than their corresponding AWT/Swing managers
    2) Most other graphics, including 2D graphics, are faster in AWT/Swing than SWT.
    I am sure that SWT encapsulates some good ideas. However, it seems that if the efficiency of validation and layouts could be improved, then AWT/Swing performance would be excellent, while maintaining OO and platform-independent characteristics.
    Possibly, these issues could be worked out piecemeal. For example, a new, rational set of layout managers could be developed entirely independently.
    Other issues, such as defining how UIs, L&F, and component classes should be architected, are going to be more problematic. Creating order in the current chaos will be difficult.
    Any ideas?

    >
    How would one go about proposing such a thing and
    getting Sun's support?
    As for proposing such a thing, you can always become a member of the Java Community Process Program (it's free for individual members): http://www.jcp.org/en/home/index. As a member you can post a Java Specification Request with your suggestions. If you want to operate on a smaller scale you can report bugs to the bug database.
    As for getting Sun's support....well, good luck! :-)

  • (Youtube-) Video in a Swing GUI

    Hey everyone,
    I'm currently trying to play a video in my Swing GUI with JMF but I really can't get it to work.
    With the help of google I got this far:
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.media.CannotRealizeException;
    import javax.media.Manager;
    import javax.media.NoPlayerException;
    import javax.media.Player;
    import javax.swing.JFrame;
    public class MediaPanel extends JFrame {
        public MediaPanel() {
            setLayout(new BorderLayout()); // use a BorderLayout
            // Use lightweight components for Swing compatibility
            Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
            URL mediaURL = null;
            try {
                mediaURL = new URL("http://www.youtube.com/watch?v=Q7_Z_mQUBa8");
            } catch (MalformedURLException ex) {
                System.err.println(ex);
            try {
                // create a player to play the media specified in the URL
                Player mediaPlayer = Manager.createRealizedPlayer(mediaURL);
                // get the components for the video and the playback controls
                Component video = mediaPlayer.getVisualComponent();
                Component controls = mediaPlayer.getControlPanelComponent();
                if (video != null) {
                    add(video, BorderLayout.CENTER); // add video component
                if (controls != null) {
                    add(controls, BorderLayout.SOUTH); // add controls
                mediaPlayer.start(); // start playing the media clip
            } // end try
            catch (NoPlayerException noPlayerException) {
                System.err.println("No media player found");
            } // end catch
            catch (CannotRealizeException cannotRealizeException) {
                System.err.println("Could not realize media player");
            } // end catch
            catch (IOException iOException) {
                System.err.println("Error reading from the source");
            } // end catch
        } // end MediaPanel constructor
    }But all I get is errors:
    Warning: The URL may not exist. Please check URL
    No media player found
    Can you please please help me get this working? I would really appreciate a little walkthrough
    Best regards,
    Patrick
    Edited by: 954807 on Aug 24, 2012 6:52 AM

    Just use \ tags. People don't like to go to external sites.
    I really advise you to consider using JavaFX 2 here. Swing is old and not really supported anymore, JMF is also old and absolutely not supported anymore.                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Embedding applets in Swing GUI?

    I'm pretty new to developing with Swing.
    I want to know what I would need to do in order to embed an applet inside a Swing GUI (if this is possible). I've looked around, but can't seem to find anything with an answer to my question.
    Any help would be greatly appreciated.

    import javax.swing.*;
    import java.applet.Applet;
    import java.awt.Label;
    /** Simplistic example of putting an Applet in a JFrame. */
    public class AppletInSwingGui extends Applet {
      public void init() {
        add( new Label("I am an applet!") );
      public static void main(String[] args) {
        final AppletInSwingGui applet = new AppletInSwingGui();
        // very important!
        applet.init();
        Runnable r = new Runnable() {
          public void run() {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add( applet );
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        SwingUtilities.invokeLater(r);
    }Note that if the applet uses the functionality of the AppletContext, the programmer needs to implement it. Some of the Applet specific methods (like getDocumentBase() and getCodeBase()) are also a bit tricky.
    Edited by: AndrewThompson64 on May 20, 2008 12:37 PM

  • Java Swing GUI Button Image

    Hi, I really need help with this one, I have tried many things and looked at many pages for this but to no avail as of yet.
    I have a Swing GUI in which I want to display an image. The way I am displaying it at the moment is as a button icon as I do not need to be able to alter the images. I can also use the button functionality as displaying something when the image is clicked. So I have an array of image paths which are accesed to load an image into the button and a "Next" button to change the image as required.
    My problem is that when I load an image into the button it moves from it's original location. When there is no image displayed the button is where I want it to be, but when I load an image it moves, this cannot happen. Any ideas.
    Also, when I am trying to click thru the array of images, it starts at the 1st image in the array but then skips to the last image in the array. Here is the code for that.
    // Handle events that arise from the "Next" button being clicked
    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {
    if (jComboBox1.getSelectedIndex() == 1)
         for (int i = 1; i < juniorImageIndex.length; i++)
         jButton8.setIcon(new javax.swing.ImageIcon(juniorImageIndex));
    else if (jComboBox1.getSelectedIndex() == 2)
         for (int i = 1; i < seniorImageIndex.length; i++)
         jButton8.setIcon(new javax.swing.ImageIcon(seniorImageIndex[i]));
    juniorImageIndex and seniorImageIndex are obviuosly the arrrays with the file paths for the images. The reason I start at index 1 is that I use the 0 index image as the starting image for each part.
    Any help gratefully appreciated, I really hope someone can help, Thanks.

    // Handle events that arise from the "Next" button
    being clicked
    private void
    jButton5MouseClicked(java.awt.event.MouseEvent evt) {
      myImageIndex =(myImageIndex + 1) % imageArray.size();
      resetButtonImage();
    private void resetButtonImage() {
    if (jComboBox1.getSelectedIndex() == 1)
    {//take this out
    //> for (int i = 1; i < juniorImageIndex.length; i++)
    //> {
    jButton8.setIcon(new//> javax.swing.ImageIcon(array[myImageIndex]));
    //> }
    else if (jComboBox1.getSelectedIndex() == 2)
    {//this too
    //> for (int i = 1; i < seniorImageIndex.length; i++)
    //> {
    jButton8.setIcon(new
    javax.swing.ImageIcon(array2[myImageIndex]));//> }

  • Swing/GUI Strategy

    My Swing GUI has a JMenuBar with several items. The main panel has a "controls" pane and an "results" pane. The results must be displayed when selecting options/actions on the "controls" pane.
    However, I want the contents of the "controls" pane to depend on the menu item selected.
    What should be my strategy to achieve this?
    My best guess would be to create all of the "controls" panes and only show one of them when using the menu. But I need a litlle bit more help on this.
    Thanks,
    joozju

    CardLayout seems helpful. Although I seem to have some problem with the cl.show() method. The other cards are not drawn when I select a menuitem:
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.KeyStroke;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test implements ActionListener {
    JPanel controlCardsPanel;
    JPanel ccDef, ccOne, ccTwo;
    public static void main(String[] args) {
    try{
    UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (UnsupportedLookAndFeelException e) {
    e.printStackTrace();
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (InstantiationException e) {
    e.printStackTrace();
    } catch (IllegalAccessException e) {
    e.printStackTrace();
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    private static void createAndShowGUI() {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("Test - Under Construction");
    Test t = new Test();
    frame.setJMenuBar(t.createMenuBar());
    frame.setContentPane(t.createContentPane());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
    public JPanel createContentPane() {
    JPanel jp = new JPanel(new BorderLayout(5,5)); //BorderLayout must be defined here
    jp.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
    jp.setPreferredSize(new Dimension(640, 480));
    jp.setBackground(Color.LIGHT_GRAY);
    ccDef = new JPanel();
    ccDef.add(new JLabel("Use the Menu"));
    ccOne = new JPanel();
    ccOne.add(new JLabel("Press One"));
    ccOne.add(new JButton("One"));
    ccTwo = new JPanel();
    ccTwo.add(new JLabel("Select Two"));
    ccTwo.add(new JCheckBox("High"));
    ccTwo.add(new JCheckBox("Low"));
    CardLayout cl = new CardLayout();
    controlCardsPanel = new JPanel();
    controlCardsPanel.setLayout(cl);
    controlCardsPanel.add(ccDef, "I am ccDefault");
    controlCardsPanel.add(ccOne, "I am ccOne");
    controlCardsPanel.add(ccTwo, "I am ccTwo");
    jp.add(controlCardsPanel, BorderLayout.LINE_START);
    jp.setOpaque(true);
    return jp;
    public JMenuBar createMenuBar() {
    //Create menu bar
    JMenuBar jmb = new JMenuBar();
    //Build File menu
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    //Add Control One MenuItem
    JMenuItem fileMenuControlOne = new JMenuItem("Card One");
    fileMenuControlOne.setActionCommand("ccOne");
    fileMenuControlOne.addActionListener(this);
    fileMenu.add(fileMenuControlOne);
    //Add Control Two MenuItem
    JMenuItem fileMenuControlTwo = new JMenuItem("Card Two");
    fileMenuControlTwo.setActionCommand("ccTwo");
    fileMenuControlTwo.addActionListener(this);
    fileMenu.add(fileMenuControlTwo);
    //Add Quit MenuItem
    JMenuItem fileMenuQuit = new JMenuItem("Quit");
    fileMenuQuit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
    fileMenuQuit.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    System.exit(0);
    fileMenu.add(fileMenuQuit);
    jmb.add(fileMenu);
    return jmb;
    public void actionPerformed(ActionEvent ae) {
    CardLayout cl = (CardLayout)(controlCardsPanel.getLayout());
    cl.show(controlCardsPanel, (String)ae.getActionCommand());
    }I expect the othe cards to appear when I select "Card One" from the File menu. But they don't. I use the Ctrl-F11 key in eclipse when I test my app.
    Thanks,
    Joost

  • Loading large files in Java Swing GUI

    Hello Everyone!
    I am trying to load large files(more then 70 MB of xml text) in a Java Swing GUI. I tried several approaches,
    1)Byte based loading whith a loop similar to
    pane.setText("");
                 InputStream file_reader = new BufferedInputStream(new FileInputStream
                           (file));
                 int BUFFER_SIZE = 4096;
                 byte[] buffer = new byte[BUFFER_SIZE];
                 int bytesRead;
                 String line;
                 while ((bytesRead = file_reader.read(buffer, 0, BUFFER_SIZE)) != -1)
                      line = new String(buffer, 0, bytesRead);
                      pane.append(line);
                 }But this is gives me unacceptable response times for large files and runs out of Java Heap memory.
    2) I read in several places that I could load only small chunks of the file at a time and when the user scrolls upwards or downwards the next/previous chunk is loaded , to achieve this I am guessing extensive manipulation for the ScrollBar in the JScrollPane will be needed or adding an external JScrollBar perhaps? Can anyone provide sample code for that approach? (Putting in mind that I am writting code for an editor so I will be needing to interact via clicks and mouse wheel roatation and keyboard buttons and so on...)
    If anyone can help me, post sample code or point me to useful links that deal with this issue or with writting code for editors in general I would be very grateful.
    Thank you in advance.

    Hi,
    I'm replying to your question from another thread.
    To handle large files I used the new IO libary. I'm trying to remember off the top of my head but the classes involved were the RandomAccessFile, FileChannel and MappedByteBuffer. The MappedByteBuffer was the best way for me to read and write to the file.
    When opening the file I had to scan through the contents of the file using a swing worker thread and progress monitor. Whilst doing this I indexed the file into managable chunks. I also created a cache to further optimise file access.
    In all it worked really well and I was suprised by the performance of the new IO libraries. I remember loading 1GB files and whilst having to wait a few seconds to perform the indexing you wouldn't know that the data for the JList was being retrieved from a file whilst the application was running.
    Good Luck,
    Martin.

  • Running a Java application from a Swing GUI

    Hi,
    I was wondering if there is a simple way to run a Java application from a GUI built with Swing. I would presume there would be, because the Swing GUI is a Java application itself, technically.
    So, I want a user to click a button on my GUI, and then have another Java application, which is in the same package with the same classpaths and stuff, run.
    Is there a simple way to do this? Do any tutorials exist on this? If someone could give me any advice, or even a simple "yes this is possible, and it is simple" or "this is possible, but difficult" or "no this is not possible" answer, I would appreciate it. If anyone needs more information, I'll be happy to provide it.
    Thanks,
    Dan

    I don't know if it is possible to run the main method from another Java app by simply calling it...
    But you could just copy and paste the stuff from your main method into a new static method called something like runDBQuery and have all the execution run from there.
    How does that sound? Is it possible?
    What I'm suggeting is:
    Original
    public class DBQuery{
    public static void methodA(){
    public static void doQuery(){
    methodA();
    public static void main(String[] args){
    // Your method calls
    //Your initializing
    doQuery();
    }Revised:
    public class DBQuery{
    public static void methodA(){
    public static void doQuery(){
    methodA();
    public static void doMyQuery(){
    // Your method calls
    //Your initializing
    doQuery();
    // No main needed!!
    //public static void main(String[] args){
    // Your method calls
    //doQuery();
    //}

  • Help on right mouse click in swing GUI.

    I am working on a swing GUI interface which has Panels. One Panel contains two sub panels. I want to add the Right Mouse click feature to the panels. How should i go about achieving this? Please provide sample example if any.
    Thanks in advance.

    anyPanel.addMouseListener(new MouseAdapter(){
       public void mouseReleased(MouseEvent e){
          if(e.isPopupTrigger()){
              // right clicked
    });

  • Awt swing 1.1

    Hi,
    Where can I actually download AWT swing 1.1 package to run with jdk 1.1.?

    http://java.sun.com/products/archive/jfc/1.1.1/index.html

  • In this case, can I modify swing GUI out of swing thread?

    I know the Swing single thread rule and design (Swing is not thread safe).
    For time-consuming task, we are using other thread to do the task and
    we use SwingUtilities.invokeAndWait() or SwingUtilities.invokeLater (or SwingWorker) to update Swing GUI.
    My problem is, my time-consuming task is related to Swing GUI stuff
    (like set expanded state of a huge tree, walk through entire tree... etc), not the classic DB task.
    So my time-consuming Swing task must executed on Swing thread, but it will block the GUI responsivity.
    I solve this problem by show up a modal waiting dialog to ask user to wait and
    also allow user to cancel the task.
    Then I create an other thread (no event-dispatch thread) to do my Swing time-consuming tasks.
    Since the modal dialog (do nothing just allow user to cancel) is a thread spawn by
    Swing event-dispatch thread and block the Swing dispatch-thread until dialog close.
    So my thread can modify Swing GUI stuff safely since there are no any concurrent access problem.
    In this case, I broke the Swing's suggestion, modify Swing stuff out of Swing event-dispatch thread.
    But as I said, there are no concurrent access, so I am safe.
    Am I right? Are you agree? Do you have other better idea?
    Thanks for your help.

    If you drag your modal dialog around in front of the background UI, then there is concurrent access: paint requests in your main window as the foreground window moves around.

  • How to display multiple tables from database using netbeans swing gui

    plz reply asap on how to display multiple tables from database using netbeans swing gui into the same project

    Layered Pane with JTables or you can easily to it with a little scripting and HTML.
    plzzzzzzzzzzzzzzzzz, do not use SMS speak when posting.

  • Spreadsheets and SWING GUI's

    I have to embed a spreadsheet facility in a SWING GUI, what is the best and easiest way to do this ??

    I am not quite sure what your problem is.
    The way I see it, your question is one of the following:
    1. How do I (generally) make a user interface on top of my dos-based program?
    2. How do I make user interfaces in swing?
    If your question is the first, I'm afraid I can't tell you either. Would seem pretty obvious to me, make a simple dialog based app, using menu's or actions to trigger tha actions that were formerly triggered by numbers, etc...
    In the other case, I recommend the java swing tutorial at http://java.sun.com/docs/books/tutorial/uiswing/
    Greetings,
    Gert

  • Creating Undo Menu on Swing GUI

    Undo Menu is to be Created on Swing GUI on the Graphics. In the Tutorial, Undo with Text is given. But on implementing the logic of Undo with Text , some Errors come.

    You can use javax.swing.undo.* stuff only with classes implementing
    javax.swing.text.Document interface.
    To add undo/redo functionality for some Graphic components you should program this mechanism by yourself.
    So create your own object model, track all changes and implement/add appropriate listeners.

  • Need help with threading in Swing GUI !!!

    I've written an app that parses and writes
    files. I'm using a Swing GUI. The app
    could potenially be used to parse hundreds or even
    thousands of files. I've included a JProgressBar
    to monitor progress. The problem is when I parse
    a large number of files the GUI freezes and only
    updates the values of the progress bar when the
    parsing and writing process is finished.
    I assume I need to start the process in a seperate thread. But, I'm new to threads and I'm not sure
    whether to start the Progressbar code in a seperate
    thread or the parsing code. As a matter of fact I really
    don't have any idea how to go about this.
    I read that Swing requires repaints be done in the
    event dispatch thread. If I start the parsing in a seperate
    thread how do I update the progressbar from the other
    thread? I'm a thread neophyte.
    I need a cigarette.

    In other words do this:
    Inside event Thread:
    handle button action
    start thread
    return from action listener
    Inside worker Thread:
    lock interface
    loop
    perform action
    update progress bar
    unlock interface
    return from worker ThreadDoesn't updating the progress bar (and locking/unlocking the interface components) from within the worker thread violate the rule that you shouldn't mess with Swing components outside the event thread? (Do I have that rule right?)
    In any case, is there any way to just post some kind of event to the progress bar to update it from within the worker thread, thereby insuring that the GUI progress bar update is being invoked from the event thread? This would also obviate the need to use a timer to poll for an update, which I think is a waste especially when the monitored progress is at a variable rate, (or for number crunching, is executing on different speed machines).
    Also, doesn't using invokeLater() or invokeAndWait() still block the event dispatching thread? I don't understand how having a chunk of code started in the event thread doesn't block the event thread unless the code's executed in a "sub-thread", which would then make it not in the event thread.
    I'm also looking to have a progress bar updated to monitor a worker thread, but also want to include a "Stop" button, etc. and need the event queue not to be blocked.
    The last thing I can think of is to implement some kind of original event-listener class that listens to events that I define, then register it with the system event queue somehow, then have the worker thread post events to this listener which then calls setValue() in the progress bar to insure that the bar is updated from the event queue and when I want it to be updated. I don't know yet if it's possible to create and register these kinds of classes (I'm guessing it is).
    Thanks,
    Derek

Maybe you are looking for