swingx
  1. swingx
  2. SWINGX-1410

Flickering in JXPanel with alpha < 1

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 1.6.2
    • Fix Version/s: 1.6.3
    • Component/s: Misc Component
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      75

      Description

      This is the first time I have filed an issue. If I am doing anything wrong,
      could you please comment to me at glennl20@cox.net Thank you.

      I believe the problem has something to do with the repaint manager since the
      problem only appears after I use a JXPanel with alpha <1. Using a JPanel or a
      JXPanel with alpha = 1 shows no ill effects.

      When resizing the JFrame when using the following code, I have found the
      results to be system dependent. On my Windows 7 – using Aero and just plain
      Windows7 – I get lots and lots of flicker. If I do not let go of the frame and
      just continue resizing, things get much worse and the flickering changes to
      completely blank areas. Sometimes the buttons trun completely black before
      repainting. After resizing, everything is displayed correctly. On the XP
      Professional system that I have access to, there is no repaint problem. On my
      XP laptop, I get an "animated" border when I resize the JFrame, but none of the
      flicker.

      Thanks in advance

      [code]

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import org.jdesktop.swingx.JXPanel;

      public class JFrameWithJXPanelTest {
      private int iScreen = 55;
      private int iLocation = 10;
      JLayeredPane layerPane = new FilledJLayeredPane();

      JFrame frame = new JFrame();
      Container contentPane = frame.getContentPane();

      public JFrameWithJXPanelTest() {

      final JXPanel jxp = new JXPanel();
      jxp.setLayout(new GridLayout());
      JLabel j2 = new JLabel(" I'm a JXPanel ");
      j2.setFont(new Font("Bookman Old Style", 3, 35));
      j2.setBackground(Color.YELLOW);
      j2.setOpaque(true);
      jxp.add(j2);
      jxp.setAlpha(0.3f);
      jxp.setBorder(javax.swing.BorderFactory.createLineBorder(Color.BLACK,
      40));

      Timer fadeTimer = new Timer(45, new ActionListener() {
      public void actionPerformed(ActionEvent arg0)

      { jxp.setAlpha(1.0f); }


      });
      fadeTimer.setInitialDelay(5000);
      fadeTimer.setRepeats(false);
      fadeTimer.start();

      contentPane.add(jxp, BorderLayout.CENTER);

      JPanel northButtonPanel = new JPanel();
      northButtonPanel.setLayout(new GridLayout(2, 2));
      northButtonPanel.add(new JButton(" I do nothing"));
      northButtonPanel.add(new JButton(" I do nothing"));
      northButtonPanel.add(new JButton(" I do nothing"));
      northButtonPanel.add(new JButton(" I do nothing"));
      // northButtonPanel.setBackground(Color.DARK_GRAY);
      contentPane.add(northButtonPanel, BorderLayout.NORTH);
      JPanel southButtonPanel = new JPanel();
      southButtonPanel.setLayout(new GridLayout(2, 2));
      southButtonPanel.add(new JButton(" I do nothing"));
      southButtonPanel.add(new JButton(" I do nothing"));
      southButtonPanel.add(new JButton(" I do nothing"));
      southButtonPanel.add(new JButton(" I do nothing"));
      // northButtonPanel.setBackground(Color.DARK_GRAY);
      contentPane.add(southButtonPanel, BorderLayout.SOUTH);
      JPanel eastButtonPanel = new JPanel();
      eastButtonPanel.setLayout(new GridLayout(2, 2));
      eastButtonPanel.add(new JButton(" I do nothing"));
      eastButtonPanel.add(new JButton(" I do nothing"));
      eastButtonPanel.add(new JButton(" I do nothing"));
      eastButtonPanel.add(new JButton(" I do nothing"));

      contentPane.add(eastButtonPanel, BorderLayout.EAST);

      /*

      • Below is the code to intialize and show the JFrame.
        */
        boolean packFrame = false;
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = frame.getSize();
        frameSize.height = (int) (iScreen * screenSize.height / 100);
        frameSize.width = (int) (iScreen * screenSize.width / 100);
        frame.setSize(frameSize);
        frame.setLocation((screenSize.width - frameSize.width) / iLocation,
        (screenSize.height - frameSize.height) / iLocation);
        if (packFrame) { frame.pack(); packFrame = true; }

        else

        { frame.validate(); }


        frame.setVisible(true);
        }

      /**

      • @param args
        */
        public static void main(String[] args) {
        try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName ()); }

        catch (Exception e)

        { e.printStackTrace(); }


        javax.swing.SwingUtilities.invokeLater(new Runnable()

        Unknown macro: { public void run() { new JFrameWithJXPanelTest(); } }

        );
        }

      private class FilledJLayeredPane extends JLayeredPane {
      private static final long serialVersionUID = 1L;
      /**

      • Layout each of the components in this JLayeredPane so that they all
      • fill the entire extents of the layered pane – from (0,0) to
      • (getWidth(), getHeight())
      • from R Camick at CodeRanch
        */
        @Override
        public void doLayout() {
        super.doLayout();
        // Synchronizing on getTreeLock, because I see other layouts
        doing
        // that.
        // see BorderLayout::layoutContainer(Container)
        synchronized (getTreeLock()) {
        int w = getWidth();
        int h = getHeight();
        for (Component c : getComponents())
        Unknown macro: { if (getLayer(c) == JLayeredPane.DEFAULT_LAYER) { c.setBounds(0, 0, w , h ); c.doLayout(); } if (getLayer(c) == JLayeredPane.PALETTE_LAYER) { c.setBounds(0, 0, w + 2, h + 2); c.doLayout(); } }


        }
        }
        }
        }

      [/code]

        Activity

        Hide
        Karl Schaefer added a comment -

        Duplicate of SWINGX-1336.

        Show
        Karl Schaefer added a comment - Duplicate of SWINGX-1336 .

          People

          • Assignee:
            Karl Schaefer
            Reporter:
            justthemath
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: