JFrame is not repainted?

If I write any Java program which does mostly heavy I/O and want to report progress by updating a window with a record count (or use a JProgressBar), the call to update the window never happens until all the I/O has finished. If have tried using a separate thread, with higher priority, but that does not help. What am I doing wrong?

You cannot perform long-running tasks (such as I/O) on the Event Dispatch Thread (the main GUI thread). If you do, the GUI will not be able to update itself until your task completes, as you have seen.
The short answer is: Do your I/O in a separate Thread. javax.swing.SwingWorker was designed for this task. If you're doing stuff on a separate Thread, keep in mind that (most) all of Swing is not threadsafe, and Swing methods should be called on the Event Dispatch Thread. This can be done via SwingUtilities.invokeLater(), or by proper use of SwingWorker.
Longer answer: read this: [Lesson: Concurrency in Swing|http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html] .
If you believe you're following these rules and still having trouble, post an SSCCE for assistance.

Similar Messages

  • JPanel not repainting if embedded in another panel

    I have a reusable class called as DuplicatorPanel. This class has two add/ remove buttons like in Mac if you are familiar.
    The problem is that the screen gets updated with an extra row in case i have a main method in Duplicator itself. However if i have that in another panel as in HyperlinkBuilder then it does not repaint itself.
    Please can someone help ?
    package sam.dnd;
    import java.awt.event.ActionEvent;
    import java.util.Iterator;
    import java.util.LinkedHashMap;
    import java.util.Map;
    import javax.swing.AbstractAction;
    import javax.swing.Action;
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    public abstract class DuplicatorPanel extends Box {
        private static final long serialVersionUID = 1L;
        private static int oneup = 0;
        private Map<String, JComponent> panelMap = new LinkedHashMap<String, JComponent>();
        private Action addAction;
        private Action removeAction;
        public DuplicatorPanel() {
            super(BoxLayout.Y_AXIS);
            this.initComponents();
            this.placeComponents();
        private void initComponents() {
            addAction = new AddAction();
            removeAction = new RemoveAction();
            addDuplicatorPanel();
        private void placeComponents() {
            Iterator<JComponent> itr = this.panelMap.values().iterator();
            while(itr.hasNext()) {
                JComponent comp = (JComponent) itr.next();
                this.add(comp);
            this.add(Box.createVerticalGlue());
        private void addDuplicatorPanel() {
            int index = oneup++;
            JComponent component = this.createDuplicate();
            JButton btnAdd = new JButton("Add");
            btnAdd.setActionCommand("" + index);
            btnAdd.addActionListener(this.addAction);
            JButton btnRemove = new JButton("Remove");
            btnRemove.setActionCommand("" + index);
            btnRemove.addActionListener(this.removeAction);
            Box box = Box.createHorizontalBox();
            box.add(component);
            box.add(Box.createHorizontalGlue());
            box.add(btnAdd);
            box.add(btnRemove);
            this.panelMap.put("" + index, box);
            fireValueChanged();
        private void fireValueChanged() {
            this.removeAll();
            this.placeComponents();
            this.repaint();
        protected void doAdd() {
            addDuplicatorPanel();
            fireValueChanged();
        protected void doRemove(String key) {
            if(this.panelMap.size() == 1) {
                return;
            JComponent comp = this.panelMap.remove(key);
            if(comp != null) {
                this.fireValueChanged();
        protected abstract JComponent createDuplicate();
        class AddAction extends AbstractAction {
            private static final long serialVersionUID = 1L;
            public void actionPerformed(ActionEvent evt) {
                doAdd();
        class RemoveAction extends AbstractAction {
            private static final long serialVersionUID = 1L;
            public void actionPerformed(ActionEvent evt) {
                JButton source = (JButton) evt.getSource();
                doRemove(source.getActionCommand());
         * @param args
        public static void main(String[] args) {
            JFrame f = new JFrame();
            f.add(new MyDuplicatorPanel());
            f.setSize(200, 200);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setVisible(true);
        static class MyDuplicatorPanel extends DuplicatorPanel {
            private static final long serialVersionUID = 1L;
            public JComponent createDuplicate() {
                return new JLabel("Test");
    }This is another class that calls the above
    package sam.dnd;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.util.HashMap;
    import javax.swing.JComboBox;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class HyperLinkBuilder extends JPanel {
        private static final long serialVersionUID = 1L;
         * @param args
        public static void main(String[] args) {
            JFrame f = new JFrame();
            f.add(new HyperLinkBuilder());
            f.setSize(200, 200);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setVisible(true);
        private static HashMap<String, String> linkNameValueMap = new HashMap<String, String>();
        private static HashMap<String, String> paramNameValueMap = new HashMap<String, String>();
        private static HashMap<String, String> valueNameValueMap = new HashMap<String, String>();
        static {
            linkNameValueMap.put("Name1", "Value1");
            linkNameValueMap.put("Name2", "Value2");
            linkNameValueMap.put("Name3", "Value3");
            paramNameValueMap.put("Name1", "Value1");
            paramNameValueMap.put("Name2", "Value2");
            paramNameValueMap.put("Name3", "Value3");
            valueNameValueMap.put("Name1", "Value1");
            valueNameValueMap.put("Name2", "Value2");
            valueNameValueMap.put("Name3", "Value3");
        private String link;
        private JComboBox linkCombo;
        private DuplicatorPanel panel;
        public HyperLinkBuilder() {
            this.initComponents();
            this.placeComponents();
            this.addListeners();
        private void initComponents() {
            linkCombo = new JComboBox(linkNameValueMap.keySet().toArray());
            panel = new MyDuplicatorPanel();
        private void placeComponents() {
            this.setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = 0;
            this.add(linkCombo, gbc);
            gbc.gridy++;
            gbc.fill = GridBagConstraints.BOTH;
            this.add(panel, gbc);
        private void addListeners() {
            this.linkCombo.addItemListener(new LinkSelector());
        private JPanel createNameValuePanel() {
            JComboBox nameCombo = new JComboBox(paramNameValueMap.keySet().toArray());
            JComboBox valueCombo = new JComboBox(valueNameValueMap.keySet().toArray());
            JPanel panel = new JPanel();
            panel.add(nameCombo);
            panel.add(valueCombo);
            return panel;
        private void doLinkSelected() {
            String name = (String) linkCombo.getSelectedItem();
            link = linkNameValueMap.get(name);
        public String build() {
            //TODO:
            return this.link;
        class LinkSelector implements ItemListener {
            public void itemStateChanged(ItemEvent e) {
                doLinkSelected();
        class MyDuplicatorPanel extends DuplicatorPanel {
            private static final long serialVersionUID = 1L;
            @Override
            protected JComponent createDuplicate() {
                return HyperLinkBuilder.this.createNameValuePanel();
    }

    Hey Xeon,
    Replace that repaint() with revalidate. That is the trick in there.
    -Sam

  • Auto-scrolling doesn't work when JFrame is not visible

    Hi, I have auto-scrolling implemented for my JTextPane that sits in JScrollPane - which lives in JInternalFrame. It works as excepted - as long as my application's JFrame is visible. When the JFrame becomes invisible, auto-scrolling simply doesn't work anymore.
    I've overcame this by scrolling down in "windowShown", but it's ugly because the user can visually see the scroll down when using this workaround (it jumps).
    I guess this is Swing's optimization, but I would really like to overcome it in someway. But it seems I'm not enough a swing hacker to do it.
    One thing to note is thtat, the auto-scrolling works fine when the JInternalFrame is NOT visible, but frame is.
    I've tried to override the isShowing-method of JInternalFrame, with no luck.
    Here's my scrolling method:
    public static void scrollDown(JScrollPane scroll) {
              JViewport port = scroll.getViewport();
              Rectangle rect = new Rectangle(0, port.getViewSize().height, 1, 1);
              port.scrollRectToVisible(rect);
              JScrollBar bar = scroll.getVerticalScrollBar();
              bar.setValue(bar.getMaximum() - bar.getModel().getExtent());
         }Anyone have ideas?

    At some point I had really hard time getting the auto-scrolling to work, as I got these weird little bumps after scrolling down.
    Adding scrollBar.setValue() seemed to 'just fix it'. It actually seems to be superfluous now.
    The scrolling is already wrapped in SwingUtilities.invokeLater() - in conjuction with printing text into the JTextPane and it works OK.
    I had some wrong info in the first post, the viewport actually does get scrolled down even when the JFrame is not visible. And by visible I mean JFrame.setVisible(false) - my application has a minimize-to-tray feature, which hides the JFrame.
    So I think the problem is 'just' a repainting problem. When the frame is shown, the previous scroll location is first displayed, and then a repaint is triggered that causes the 'jump down'.
    I'm not still sure how to fix it though.

  • Application's main window is not repainted

    Hello everybody.
    The system I am using
    Product Version: NetBeans IDE 6.5 (Build 200811100001)
    Java: 1.6.0_12; Java HotSpot(TM) Client VM 11.2-b01
    System: Windows Vista version 6.0 running on x86; Cp1251; ru_RU (nb)I created Java Desktop application (New project - Java Desktop Application (no CRUD)) and put a JTable like this:
    mainPanel[JPanel]
        jScrollPane1[JScrollPane]
            jTable1[JTable]
    I did not do anything more. But after building project I have a problem with my application - main window does not repaint itself after another window is positioned over it(calculator, for example). It repaints only after I resized main window or something like that ...
    What am I doing wrong?
    Thank you.

    I found a solution - to resolve this bug I have to set -Dsun.java2d.noddraw=true VM flag.
    I found the same bug in a database - [4139083|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4139083] and it's submit date is *15-MAY-1998* !!!
    There is also an issue about that kind of a problem - [6343853|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6343853], submit date 31-OCT-2005.
    So, I guess unfortunately there are a lot of things to think about ...

  • Whole screen is not repainted, need debug tips

    We are running an application which uses some jogl for animaties.
    Sometimes when the animation is finished and we set the GLCanvas to invisible, the normal
    java JPanels are not repainted.
    Also alt-tab to another windows application and back will not force a redraw.
    The application itself is still working, clicking on a (now) not visible button will trigger
    the jogl animations, and these are show correctly.
    Also from logging it appear that the AWT-thread is not blocking.
    We are looking for tips that can help find us the problem from logging
    as it only appears a few times a week and it is not reproducable.

    The problem is that most of the time it works, but after some hours/days, the java panels are not repainted.
    There is no memory leak.
    paintComponent is not overwritten, a object is made visible to do the animation.
    Pseudo code:
    public class AnimateTilePopup extends JPanel {
    GLCanvas glCanvas;
    public AnimateTilePopup() {
    super(null);
    setOpaque(true);
    glCanvas = new GLCanvas();
    glCanvas.setLocation(0,0);
    glCanvas.setSize(width, height);
    glCanvas.setVisible(false);
    glCanvas.setFocusable(false);
    add(glCanvas);
    flipRendererZoom = new AnimateRendererZoom();
    glCanvas.addGLEventListener(flipRendererZoom);
    public startAnimation() {
    glCanvas.setVisible(true);
    this.setVisible(true);
    public stopAnimation() {
    glCanvas.setVisible(false);
    this.setVisible(false);
    So sometimes when we call stopAnimation(), the animation is stoppped, but the underlying java JPanels are not repainted.
    When we now call startAnimation, the animation is shown and when stopped, no repaint for the normal JPanels.
    Most times it is working perfectly, only sometimes it failes.
    What can be the cause or what logging can be gather that might gives us a clue how to fix this problem.

  • After GLcanvas setVisible(false), normal JPanels sometimes not repainted.

    We are running an application which uses some jogl for animaties.
    Sometimes when the animation is finished and we set the GLCanvas to invisible, the normal
    java JPanels are not repainted.
    Also alt-tab to another windows application and back will not force a redraw.
    The application itself is still working, clicking on a (now) not visible button will trigger
    the jogl animations, and these are show correctly.
    Also from logging it appear that the AWT-thread is not blocking.
    We are looking for tips that can help find us the problem from logging
    as it only appears a few times a week and it is not reproducable.

    The problem is that most of the time it works, but after some hours/days, the java panels are not repainted.
    There is no memory leak.
    Pseudo code:
    public class AnimateTilePopup extends JPanel {
    GLCanvas glCanvas;
    public AnimateTilePopup() {
    super(null);
    setOpaque(true);
    glCanvas = new GLCanvas();
    glCanvas.setLocation(0,0);
    glCanvas.setSize(width, height);
    glCanvas.setVisible(false);
    glCanvas.setFocusable(false);
    add(glCanvas);
    flipRendererZoom = new AnimateRendererZoom();
    glCanvas.addGLEventListener(flipRendererZoom);
    public startAnimation() {
    glCanvas.setVisible(true);
    this.setVisible(true);
    public stopAnimation() {
    glCanvas.setVisible(false);
    this.setVisible(false);
    So sometimes when we call stopAnimation(), the animation is stoppped, but the underlying java JPanels are not repainted.
    When we now call startAnimation, the animation is shown and when stopped, no repaint for the normal JPanels.
    Most times it is working perfectly, only sometimes it failes.
    What can be the cause or what logging can be gather that might gives us a clue how to fix this problem.

  • JFrame can not be visiable on WinXP.

    I create a frame which extends from JFrame. when a button is clicked, the frame should be visiable. On Win 2000, it runs, but on Win Xp , it does not run, the frame does not appear. But the other frame which also extends from the JFrame runs on both system. The Java SDK is version 1.4.2.
    Could anybody help me?
    coral9527

    Are the files you are trying to import mp3's? If not then either use iTunes to convert them or get some other third party program (i found a few really good ones but i can't remember what they were called). If they are mp3 maybe try converting them to mp3 again using a different encoder? (my LAME encoded ones seem to work fine)

  • JFrame does not initialize properly

    Hey, I have a method which basically creates a JFrame, and puts a couple of password fields in it etc. Nothing too special. Now the method could be called in one of two places, if the method is called in the first place, near the beginning of the program then it works perfectly fine. However if I call it later on in the program then all I get is the border around the window and the close minimize, maximize buttons. The background of the window remains completely transparent.
    This happens regardless of if the method has been called before or not.
    Has anyone seen this behaviour before? Am I not initializing something that I should be?
    I have posted the method below...
    //Changes password
         private void changePasswordGUI()
              if(debug)System.out.println("[" + this.getClass() + "]{Window Launch}change Password");
              awaitUserInput = true;
              //TODO Program icon
              //----------------------Create new password GUI----------------------
              //-----------Window
              final JFrame mainNewPassFr = new JFrame();
              final JPanel mainNewPassPa = new JPanel();
              mainNewPassFr.setContentPane(mainNewPassPa);
              mainNewPassFr.setLayout(new BorderLayout());
              final JPanel messagePa = new JPanel();
              messagePa.setBackground(Color.WHITE);
              messagePa.setLayout(new BorderLayout());
              mainNewPassPa.add(messagePa, BorderLayout.NORTH);
              final JPanel entryPa = new JPanel();
              //entryPa.setLayout(new GridBagLayout(2,2));
              mainNewPassPa.add(entryPa, BorderLayout.CENTER);
              final JPanel buttonsPa = new JPanel();
              mainNewPassPa.add(buttonsPa, BorderLayout.SOUTH);
              //-----------Setup elements
              final JLabel titleLab1 = new JLabel("  Create a password");
              titleLab1.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 16));
              titleLab1.setHorizontalTextPosition(JLabel.LEFT);
              titleLab1.setPreferredSize(new Dimension(1, 30));
              titleLab1.setForeground(new Color(0, 51, 153));
              messagePa.add(titleLab1, BorderLayout.NORTH);
              final JLabel titleLab2 = new JLabel("        This password will be used to access Password Keeper");
              titleLab2.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 14));
              titleLab2.setHorizontalTextPosition(JLabel.LEFT);
              titleLab2.setPreferredSize(new Dimension(1, 40));
              titleLab2.setForeground(new Color(0, 51, 153));
              messagePa.add(titleLab2, BorderLayout.SOUTH);
              final JLabel passwordLab1 = new JLabel("    Enter your password:");
              entryPa.add(passwordLab1);
              final JPasswordField passwordField1 = new JPasswordField(25);
              entryPa.add(passwordField1);
              final JLabel passwordLab2 = new JLabel("Confirm your password:");
              entryPa.add(passwordLab2);
              final JPasswordField passwordField2 = new JPasswordField(25);
              entryPa.add(passwordField2);
              final JLabel strengthLab = new JLabel("Password Strength: Weak");
              strengthLab.setFont(new Font(Font.DIALOG, Font.BOLD, 12));
              strengthLab.setForeground(Color.RED);
              entryPa.add(strengthLab);
              final JButton confirmButt = new JButton("Confirm");
              buttonsPa.add(confirmButt);
              mainNewPassFr.getRootPane().setDefaultButton(confirmButt);
              final JButton cancelButt = new JButton("Cancel");
              buttonsPa.add(cancelButt);
              //----------------------Listeners----------------------
              cancelButt.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        System.exit(0);
              confirmButt.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        if(passwordField1.getPassword().length > 0 && passwordField2.getPassword().length > 0)
                             if(pk.confirmPasswordsSame(passwordField1.getPassword(), passwordField2.getPassword()))
                                  mainNewPassFr.dispose();
                                  if(debug)System.out.println("[" + this.getClass() + "]User input received");
                                  //Get key from password
                                  pk.generateKey(passwordField1.getPassword());
                                  //TODO Encrypt
                                  awaitUserInput = false;
                             else
                                  passwordField1.setText("");
                                  passwordField2.setText("");
                                  mainNewPassFr.dispose();
                                  JOptionPane.showMessageDialog(null, "The passwords you entered are not the same.\n\n"+
                                            "Please try again", "Password Error", JOptionPane.ERROR_MESSAGE);
                                  mainNewPassFr.setVisible(true);
              //TODO Detect when password entered into first field only and check security
              mainNewPassFr.setSize(400,210);
              mainNewPassFr.setTitle(progName);
              mainNewPassFr.setAlwaysOnTop(true);
              mainNewPassFr.setResizable(false);
              mainNewPassFr.setLocationRelativeTo(null);
              mainNewPassFr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              mainNewPassFr.setVisible(true);
              if(debug)System.out.println("[" + this.getClass() + "]Awaiting user input");
              while(awaitUserInput)
                   try{Thread.sleep(100);}catch(Exception e){
                        JOptionPane.showMessageDialog(null, "CRITICAL ERROR: " + e +" in "+this.getClass()+"\n\nThe program will now exit.", "Critical Error", JOptionPane.ERROR_MESSAGE);
                        System.exit(1);
         }Thanks in advance

    ahh ok thank you, will investigate now that I have a starting point.
    *and noted for future posts.                                                                                                                                                                                                   

  • In Unix, main JFrame focus not regained after modal dialog exit.

    Hi all,
    I'm new to this forum so hopefully this is the right place to put this question.
    I have a relatively simple GUI application written in Java 6u20 that involves a main gui window (extends JFrame). Most of the file menu operations result in a modal dialog (either JFileChooser or JOptionPane) being presented to the user.
    The problem is that when running on Unix (HPUX), the process of changing focus to one of these modal dialogs occasionally results in a quick flash of the background terminal window (not necessarily that used to launch the Java), and the process of closing the modal dialogs (by any means, i.e. any dialog button or hitting esc) doesn't always return focus to the main extended JFrame object, sometimes it goes to the terminal window and sometimes just flashes the terminal window before returning to the main JFrame window.
    I think the problem is with the Unix window manager deciding that the main focus should be a terminal window, not my Java application, since the problem occurs in both directions (i.e. focus from main JFrame to modal dialog or vice versa).
    In most cases of JOptionPane, I DO specify that the main extended JFrame object is the parent.
    I've tried multiple things since the problem first occured, including multiple calls to a method which calls the following:
    .toFront();
    .requestFocus();
    .setAlwaysOnTop(true);
    .setVisible(true);
    ..on the main JFrame window (referred to as a public static object)...
    just before and after dialog display, and following selection of any button from the dialogs. This reduced the frequency of the problem, but it always tends to flash the terminal window if not return focus to it completely, and when it occurs (or starts to occur then gets worse) is apparently random! (which makes me think it's an OS issue)
    Any help appreciated thanks,
    Simon
    Self-contained compilable example below which has the same behaviour, but note that the problem DOESN'T occur running on Windows (XP) and that my actual program doesn't use auto-generated code generated by a guibuilder:
    * To change this template, choose Tools | Templates 
    * and open the template in the editor. 
    package example;  
    import javax.swing.JOptionPane;  
    * @author swg 
    public class Main {  
         * @param args the command line arguments 
        public static void main(String[] args) {  
            java.awt.EventQueue.invokeLater(new Runnable() {  
                public void run() {  
                    new NewJFrame().setVisible(true);  
    class NewJFrame extends javax.swing.JFrame {  
        /** Creates new form NewJFrame */ 
        public NewJFrame() {  
            initComponents();  
        /** This method is called from within the constructor to 
         * initialize the form. 
         * WARNING: Do NOT modify this code. The content of this method is 
         * always regenerated by the Form Editor. 
        @SuppressWarnings("unchecked")  
        // <editor-fold defaultstate="collapsed" desc="Generated Code">  
        private void initComponents() {  
            jMenuBar1 = new javax.swing.JMenuBar();  
            jMenu1 = new javax.swing.JMenu();  
            jMenuItem1 = new javax.swing.JMenuItem();  
            jMenu2 = new javax.swing.JMenu();  
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);  
            jMenu1.setText("File");  
            jMenuItem1.setText("jMenuItem1");  
            jMenuItem1.addActionListener(new java.awt.event.ActionListener() {  
                public void actionPerformed(java.awt.event.ActionEvent evt) {  
                    jMenuItem1ActionPerformed(evt);  
            jMenu1.add(jMenuItem1);  
            jMenuBar1.add(jMenu1);  
            jMenu2.setText("Edit");  
            jMenuBar1.add(jMenu2);  
            setJMenuBar(jMenuBar1);  
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());  
            getContentPane().setLayout(layout);  
            layout.setHorizontalGroup(  
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
                .addGap(0, 400, Short.MAX_VALUE)  
            layout.setVerticalGroup(  
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
                .addGap(0, 279, Short.MAX_VALUE)  
            pack();  
        }// </editor-fold>  
        private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {  
            int result = JOptionPane.showConfirmDialog(this, "hello");  
        // Variables declaration - do not modify  
        private javax.swing.JMenu jMenu1;  
        private javax.swing.JMenu jMenu2;  
        private javax.swing.JMenuBar jMenuBar1;  
        private javax.swing.JMenuItem jMenuItem1;  
        // End of variables declaration  
    }

    It won't comfort you much, but I had similar problems on Solaris 10, and at the time we traked them down to a known bug [6262392|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6262392]. The status of this latter is "Closed, will not fix", although it is not explained why...
    It's probably because the entry is itself related to another, more general, bug [6888200|http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=b6eea0fca217effffffffe82413c8a9fce16?bug_id=6888200], which is still open.
    So it is unclear whether this problem will be worked upon (I suspect that yes) and when (I suspect that... not too soon, as it's been dormant for several years!).
    None of our attempts (+toFront(...)+ etc...) solved the issue either, and they only moderately lowered the frequency of occurrence.
    I left the project since then, but I was said that the workaround mentioned in the first bug entry (see comments) doesn't work, whereas switching to Java Desktop instead of CDE reduced the frequency of the issues (without fixing them completely either) - I don't know whether it's an option on HPUX.
    Edited by: jduprez on Jul 9, 2010 11:29 AM

  • JFrame.dispose not firing the windowsClosing event

    No this one is not quite like the question a few posts down, well not exactly anyway.
    I have a JFrame with a windowAdapter that handles my closing tasks, it works just fine currently as long as the close button on the frame is clicked. I had to add a check in the program that should close the window if its true.
    So I have code that checks a condition and if its true it shuts down all threads and trys to exit gracefully through the windowClosing event. As other posts have said I can use the jframe.dispose followed by System.exit and it works fine seeing that in the code thoughmakes me think its a kludge since dispose doesn't trigger the windowClosing event. I would like to somehow simulate clicking the close button on the frame when I need to exit because of an error but I'm not sure how to programatically do that.
    My current window close operation is set to DO_NOTHING_ON_CLOSE so that the windowClosing event can handle the closing, I tried setting the operation to EXIT_ON_CLOSE then disposing the frame when the error occured but that didn't trigger the windowsClosing event either.
    Any ideas?
    Thanks,
    Eudaemon.

    okay... So do something like this:
    private void init() { // or whatever...
       frame.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
             quit();
       quitmenuitem.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent.) {
             quit();
    public void quit() {
       // do whatever cleanup or checks or whatever...
       frame.dispose();
    }

  • HOW TO SET A JFRAME TO NOT MOVIBLE

    How can I set a JFrame that contains several JPanel's not movible?
    Thanks.

    store the location of frame, when frame is moved set the location back
    to the original location.

  • Not repaint panel when scene moved

    hi, i have next components. JPanel, which contains JScrollPane with JLabel on it. Right now, when mouse moves over JPanel, all of those components (or at least JLabel) are repainted.
    How i can forbid repaint method on mouse moved event?

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Repaint extends MouseMotionAdapter
        JLabel report = new JLabel(" ", JLabel.CENTER);
        public static void main(String[] args)
            Repaint test = new Repaint();
            TalkingLabel label = new TalkingLabel("label");
            label.addMouseMotionListener(test);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new JScrollPane(label));
            f.getContentPane().add(test.report, "South");
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
        public void mouseMoved(MouseEvent e)
            // did you do something here to cause repainting?
            report.setText("x = " + e.getX() + "  y = " + e.getY());
    class TalkingLabel extends JLabel
        public TalkingLabel(String text)
            super(text, CENTER);
            setFont(getFont().deriveFont(18f));
            setBackground(Color.pink);
        protected void paintComponent(Graphics g)
            ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                             RenderingHints.VALUE_ANTIALIAS_ON);
            super.paintComponent(g);
            System.out.println("talking label is repainting itself");
    }

  • Not ".repaint" but .... ?

    Another simple one ....
    I have a button that calls the repaint method of MyCanvas "can" :
    if (label == "Display") {
    can.repaint();
    Now, this seems to clear my canvas and draw it again. I want it to just draw over the top of what is there already. i have tried can.paint, but get an error:
    "Error: methos paint() not found in class .....MyCanvas"
    Am I not including something or what?
    Any ideas?
    this should be as simple as anything!

    You need to define the factory method paint() in your class. The call to repaint will implicitly call this paint() method. What you can do is define the paint method with a single call to the superclass' paint method. For more on paint see: as a starting point.
    http://java.sun.com/docs/books/tutorial/applet/overview/componentMethods.html

  • Repaint() not repainting in JComponent

    This code doesn't repaint itself when one of the methods to reposition the label is called (eg labelLeft()). I could really do with knowing why not.
    <code>
    import javax.swing.*;
    import javax.swing.table.*;
    import vdt.*;
    import java.awt.*;
    public class PreviewLabel extends JComponent{
    JTable table;
    Object[] label = {"Account ID","Accounts","MoreAccounts"};
    Object[] columns = {label};
    String[] columnNames1 = {"Label"};
    JLabel icon;
    Icon ico;
    GridBagLayout gridbag;
    GridBagConstraints c;
    public PreviewLabel(Icon ico) {
    super();
    this.ico = ico;
    icon = new JLabel(ico);
    table = new JTable(new MyTableModel(columns,columnNames1));
    gridbag = new GridBagLayout();
    c = new GridBagConstraints();
    setLayout(gridbag);
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    protected void setup(JComponent comp,
    GridBagLayout gridbag,
    GridBagConstraints c) {
    gridbag.setConstraints(comp, c);
    add(comp);
    System.out.println(comp);
    public Icon getIcon(){
    return ico;
    public void setIcon(Icon icon){
    this.ico = icon;
    public void labelLeft(){
    this.removeAll();
    setup(icon, gridbag, c);
    c.gridwidth = GridBagConstraints.REMAINDER; //end row
    setup(table, gridbag, c);
    public void labelTop(){
    this.removeAll();
    c.gridwidth = GridBagConstraints.REMAINDER; //end row
    setup(icon, gridbag, c);
    setup(table, gridbag, c);
    public void labelBottom(){
    this.removeAll();
    c.gridwidth = GridBagConstraints.REMAINDER; //end row
    setup(table, gridbag, c);
    setup(icon, gridbag, c);
    repaintAll();
    public void labelRight(){
    this.removeAll();
    setup(table, gridbag, c);
    c.gridwidth = GridBagConstraints.REMAINDER; //end row
    setup(icon, gridbag, c);
    </code>

    I think you should try
    invalidate()
    validate()
    rather than repaintAll();
    When you invalidate() this calls the specific layout manager to redo the layout of the components

  • Jframe window not closing

    Hi can anyone plz tell me how i will close my jframe window..
    I have a button called EXIT,clicking which i want to close my Frame...
    I am writiing setvisible(false) but thats not working..

    use
    System.exit(0);
    All the best

Maybe you are looking for

  • Issue on the Data Form - Implied Sharing

    Hello, We have a data form on which the user can drill down till Level 0 Customer in rows to input data. The issue is for some customers when the user is trying to input the data at Level 0 Customer it is not saving the input number but was getting o

  • Help With Multiple WAPs & Multiple SSIDs

    I just inherited a wireless LAN that is using 5 1230 WAP devices, all using a single SSID configured for 1) open authentication, 2) mandatory WPA key mgmt, 3) hex SSID key, and 4) cipher TKIP encryption. Everything works fine, but now I have to add a

  • CS4...How do you draw/paint in pure black & white?

    Sorry for the dumb questions but I'm absolutely new to this stuff and I'm getting a lot of great info here which I'm keeping meticulous notes of... I've figured out how to paint with CS4 in colors and "near" black/grey/ white (by going to the extreme

  • My ipod touch Accelerometer stopped working.

    I am running 4.3.3.  Any suggestions will be appreciated. TIA.

  • OEM - Refresh Template script generation wizard don't work

    (Oracle 9.2.0.8, single-master-many-mviews) Hi, I have never trusted in OEM but this time I hoped it will help me. Alas! I created the deployment template using an OEM wizard. Now I need to generate the template script. The template script generation