This discussion is archived
6 Replies Latest reply: Jun 25, 2009 6:29 AM by 843804 RSS

setvisible with java 1.6.11 and up

843804 Newbie
Currently Being Moderated
Help please!!!

We have an application that switches out panels in a JSplitPane. One of the panels is a very large JScrolledPane and when setting the visibility to false it can lock the application 30-60 seconds. This all started happening with the 1.6.11 update. Has anyone seen this or have any clues on why?

Thanks,
Mike
  • 1. Re: setvisible with java 1.6.11 and up
    843804 Newbie
    Currently Being Moderated
    Well, after a little more digging, it is not setvisible that is the issue, it is the remove(component) that seems to be the problem.
  • 2. Re: setvisible with java 1.6.11 and up
    793415 Pro
    Currently Being Moderated
    Can you prepare an SSCCE that demonstrates the same behaviour you describe?

    And as an aside, it is rarely, if ever, necessary to call setVisible(boolean) on anything short of root (JFrame, JDialog..) components.
  • 3. Re: setvisible with java 1.6.11 and up
    843804 Newbie
    Currently Being Moderated
    Thanks for the reply. And here you go. But, now I have a bigger problem. This works for 1.5 thru 1.6.14!!! Granted our panels are move complex, but it still should not lock up the application during the remove call.

    Thanks again,
    mike

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;

    public class RemoveExample {
    static JFrame frame = new JFrame("Remove Issue");
    static JSplitPane mainPanel = new JSplitPane();
    static JSplitPane panel1 = new JSplitPane();
    static JSplitPane panel2 = new JSplitPane();

    public static void main(String args[]) {
         
         JPanel buttonPanel = new JPanel(new FlowLayout());
         JButton button = new JButton("Switch Panels");
         button.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
              if (panel1.isVisible()) {
              mainPanel.remove(panel1);
              panel1.setVisible(false);
              mainPanel.setBottomComponent(panel2);
              panel2.setVisible(true);
              } else {
              mainPanel.remove(panel2);
              panel2.setVisible(false);
              mainPanel.setBottomComponent(panel1);
              panel1.setVisible(true);
              }
         }
         });

         buttonPanel.add(button);

         mainPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
         mainPanel.setTopComponent(buttonPanel);

         panel1.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
         panel1.setLeftComponent(new JScrollPane(new JTree()));
         panel1.setRightComponent(new JLabel("small panel"));

         JTabbedPane tabs = new JTabbedPane();
         JPanel thumbnails = new JPanel(new GridLayout(0, 5, 10, 10));
         DefaultTableModel dtm = new DefaultTableModel();
         dtm.addColumn("Label");
         dtm.addColumn("Name");
         dtm.addColumn("Gallery");
         dtm.addColumn("Owner");
         dtm.addColumn("Uploaded");
         dtm.addColumn("Size(KB)");
         JTable table = new JTable(dtm);

         tabs.addTab("Thumbnails", new JScrollPane(thumbnails));
         tabs.addTab("List", new JScrollPane(table));

         panel2.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
         panel2.setLeftComponent(new JScrollPane(new JTree()));
         panel2.setRightComponent(tabs);

         mainPanel.setBottomComponent(panel1);
         
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
         frame.setSize(1000, 800);
         frame.setVisible(true);
         LoadThread loader = new LoadThread(thumbnails, table);
         loader.start();
    }

    public static class LoadThread extends Thread {
         JPanel thumbs;
         JTable table;

         public LoadThread(JPanel thumbs, JTable table) {
         this.thumbs = thumbs;
         this.table = table;
         }

         public void run() {
         DefaultTableModel dtm = (DefaultTableModel)table.getModel();
         
         for (int i = 0; i < 4000; i++) {
              JLabel label = new JLabel("image " + i);
    // set image icon.
              //label.setIcon(new ImageIcon("image.jpg"));
              label.setVerticalTextPosition(SwingConstants.BOTTOM);
              label.setHorizontalTextPosition(SwingConstants.CENTER);
              
              thumbs.add(label);
              dtm.insertRow(i, new String[]{ "image " + i, "Name", "Gallery",
                             "Owner", "Uploaded", "Size(KB)" } );
         
         }
         }
    }
    }

    Edited by: Pegasus-3326 on Jun 25, 2009 4:38 AM
  • 4. Re: setvisible with java 1.6.11 and up
    843804 Newbie
    Currently Being Moderated
    As a side note, this problem seems to be fixed with the latest 1.7 build.
  • 5. Re: setvisible with java 1.6.11 and up
    793415 Pro
    Currently Being Moderated
    >
    As a side note, this problem seems to be fixed with the latest 1.7 build.>
    What 'problem'? Your next to last post was confusing to me because you stated you now had code that worked, yet alluded to 'another' problem but neglected to mention what it was. Taxes, death, ..absent mindedness? I thought I'd wait for you to clarify.

    BTW. When posting code, code snippets, HTML/XML or input/output, please use the code tags. To do that, select the code and click the CODE button seen on the Plain Text tab of the message posting form.
  • 6. Re: setvisible with java 1.6.11 and up
    843804 Newbie
    Currently Being Moderated
    Sorry, I am new to this site, but I will get better with time. Anyway, let me start over.

    We have an application, currently in beta, that started having problems with the 6.11 and up updates. The problem is when switching out (container add/remove) very large panels. The application "hangs" for x number of seconds depending on size, one of our test cases hangs for 60 seconds. So, you asked me to put together an example of the problem. So I put something together that sort of resembled our use case. The sample code posted worked without problems, which frustrated me to no end. But, this was a very simple mock up and i did not what to leave you hanging without any reply, since you were nice enough to ask for more information. After that post, I started building out the sample code to see if I could find the breaking point; and also, decided to check for any java updates coming. Well, I found java 1.7 and decided to see what would happen. To my surprise and frustration the hanging problem went away.