Swing Ui multiplying panel ghosting

后端 未结 1 987
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-24 22:39

I\'ve got a probelm with my swing ui lately. Everything works fine,untill i trigger a tooltip from a JButton.After that moving the mouse over the rest of the ui is causing weird

相关标签:
1条回答
  • 2021-01-24 22:59

    Your code exhibits none of the glitches shown above when run on my platform.

    • Verify that you have no painting problems e.g. neglecting super.paintComponent() as discussed here.

    • Verify that you have no driver incompatibilities, as discussed here.

    • Construct and modify all GUI objects on the event dispatch thread.

    • Don't use set[Preferred|Maximum|Minimum]Size() when you really mean to override get[Preferred|Maximum|Minimum]Size(), as discussed here. The example below overrides getPreferredSize() on the scroll pane, but you can implement Scrollable, as discussed here.

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.EventQueue;
    import java.awt.GridLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JProgressBar;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    
    /** @see https://stackoverflow.com/a/34319260/230513 */
    public class MainFrame {
    
        private static final int H = 64;
    
        public static void main(String[] args) {
            EventQueue.invokeLater(() -> new MainFrame());
        }
    
        public MainFrame() {
            JFrame frame = new JFrame("LOL");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            JTabbedPane tabbedPane = new JTabbedPane();
            JPanel panel = new JPanel(new GridLayout(0, 1, 5, 5));
            for (int i = 0; i < 8; i++) {
                panel.add(new DownloadPanel());
            }
            JScrollPane jsp = new JScrollPane(panel) {
                @Override
                public Dimension getPreferredSize() {
                    return new Dimension(6 * H, 4 * H);
                }
            };
            tabbedPane.addTab("Download", null, jsp, "Main Download Window.");
            tabbedPane.addTab("Options", null, null, "Options");
            frame.add(tabbedPane);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    
        private static class DownloadPanel extends JPanel {
    
            JPanel jobPanel = new JPanel();
    
            public DownloadPanel() {
                this.setLayout(new BorderLayout());
                this.setBackground(Color.lightGray);
                JProgressBar jpb = new JProgressBar();
                jpb.setIndeterminate(true);
                this.add(jpb);
                JPanel buttonPane = new JPanel();
                JButton toggleTorConnectionButton = new JButton("Button");
                toggleTorConnectionButton.setToolTipText("Toggles Tor Connection.");
                buttonPane.add(toggleTorConnectionButton);
                this.add(buttonPane, BorderLayout.WEST);
            }
    
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(4 * H, H);
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题