0

Whenever I hover over menu items I get a weird black space as seen in the image and I am not sure why. When I use the system look and feel I don't have this problem so I think it is because of the substance look and feel.

public final class MainFrame extends JFrame {

public MainFrame(final Loader loader) {
    super(Configuration.CLIENT_NAME + " v" + Configuration.getVersion());
    try {
        Toolkit kit = Toolkit.getDefaultToolkit();
        Image img = kit.createImage(new URL(Configuration.Paths.Resources.ICON));
        setIconImage(img);
    } catch (Exception e) {
    }

    final Container c = getContentPane();
    c.setLayout(new GridBagLayout());
    ((GridBagLayout) c.getLayout()).columnWeights = new double[]{1.0, 0.0};
    ((GridBagLayout) c.getLayout()).rowWeights = new double[]{1.0};
    c.setBackground(Color.BLACK);

    final AppletPanel appletPanel = new AppletPanel(loader);
    appletPanel.reload();
    c.add(appletPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
            GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

    final JMenuBar menu = new JMenuBar();
    menu.add(new FileMenu());
    menu.add(new ViewMenu());
    menu.add(new UtilitiesMenu());
    menu.add(new PluginsMenu());
    menu.add(new LinksMenu());
    menu.add(new ScreenshotMenu());
    menu.add(new HelpMenu());
    setJMenuBar(menu);

    addWindowStateListener(new WindowStateListener() {
        public void windowStateChanged(final WindowEvent e) {
            validate();
        }
    });

    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    pack();
    setLocationRelativeTo(null);
    setVisible(true);
}

public final class AppletPanel extends JPanel {

    enum State {
        SPLASH,
        CONFIG,
        DOWNLOAD,
        IDENTIFY,
        INITIALIZE,
        ERROR,
        OSR
    }

    private static final ExecutorService pool = Executors.newFixedThreadPool(1);
    private State state = State.SPLASH;
    private volatile String error;
    private volatile Applet applet = null;
    private volatile Loader loader;

    public AppletPanel(final Loader loader) {
        super(new BorderLayout());
        this.loader = loader;
        this.setBackground(Color.BLACK);
        this.setMaximumSize(new Dimension(765, 503));
        this.setPreferredSize(new Dimension(765, 503));
        this.setSize(765, 503);
        revalidate();
    }

    public void reload() {
        synchronized (this) {
            if (state == State.CONFIG || state == State.DOWNLOAD || state == State.IDENTIFY) return;
            state = State.CONFIG;
        }
        if (applet != null) {
            remove(applet);
            applet.destroy();
            System.gc();
            applet = null;
            error = null;
        }
        pool.submit(new Runnable() {
            public void run() {
                state = State.DOWNLOAD;
                loader.load();
                state = State.INITIALIZE;
                try {
                    applet = loader.createApplet();
                } catch (Exception e) {
                    error(e.toString());
                    return;
                }
                applet.setStub(loader.getCrawler());
                applet.init();
                applet.start();
                add(applet, BorderLayout.CENTER);
                state = State.OSR;
                revalidate();
            }
        });
        new Thread(new Runnable() {
            public void run() {
                while (state != State.OSR && state != State.ERROR) {
                    repaint();
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException ex) {
                        break;
                    }
                }
                repaint();
            }
        }).start();
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        switch (state) {
            case CONFIG: {
                String message = "Loading configuration...";
                FontMetrics fm = g.getFontMetrics();
                g.setColor(Color.RED);
                g.drawString(message, getWidth() / 2 - fm.stringWidth(message) / 2, 25);
                break;
            }
            case DOWNLOAD: {
                String message = "Processing... " + loader.current();
                FontMetrics fm = g.getFontMetrics();
                g.setColor(Color.RED);
                g.drawString(message, getWidth() / 2 - fm.stringWidth(message) / 2, 175);
                g.setColor(Color.RED);
                g.drawRoundRect(getWidth() / 2 - 100, 200, 200, 50, 10, 10);
                g.fillRoundRect(getWidth() / 2 - 100, 200, (int) (loader.downloaded() * 200), 50, 10, 10);
                g.setColor(new Color(255, 255, 255, 50));
                g.fillRoundRect(getWidth() / 2 - 100, 200, 200, 35, 10, 10);
                break;
            }
            case IDENTIFY: {
                String message = "Identifying classes...";
                FontMetrics fm = g.getFontMetrics();
                g.setColor(Color.RED);
                g.drawString(message, getWidth() / 2 - fm.stringWidth(message) / 2, 25);
                g.setColor(Color.RED);
                break;
            }
            case INITIALIZE: {
                String message = "Initializing...";
                FontMetrics fm = g.getFontMetrics();
                g.setColor(Color.RED);
                g.drawString(message, getWidth() / 2 - fm.stringWidth(message) / 2, 25);
                break;
            }
            case ERROR: {
                FontMetrics fm = g.getFontMetrics();
                g.drawString(error, getWidth() / 2 - fm.stringWidth(error) / 2, 50);
                break;
            }
        }
    }

    private synchronized void error(String message) {
        state = State.ERROR;
        this.error = message;
    }

    public void setSize(final Dimension dimension) {
        super.setSize(dimension);
        if (applet != null) {
            applet.setSize(dimension);
        }
    }
}

    public void setPreferredSize(final Dimension dimension) {
        super.setPreferredSize(dimension);
        if (applet != null) {
            applet.setPreferredSize(dimension); 
        }
    }
}
BoltClock
  • 630,065
  • 150
  • 1,295
  • 1,284
  • I think this is the drop shadow handling interacting poorly with translucent/transparent windows. Possibly a video card problem. Is there a different machine you can test this on? Ideally a different PC vendor. – shemnon Nov 11 '13 at 20:06

2 Answers2

0

Use this code anywhere in your script:

System.setProperty("jgoodies.popupDropShadowEnabled", "false");

Or more correctly:

UIManager.put("jgoodies.popupDropShadowEnabled", "false");
-1

I think removing the "c.setBackground(Color.BLACK);" aswell as all of the other JFrame modifications to change the background color, would fix this by having the background transparent. As if the black area were a part of the JFrame menu you have on top, which it seems like, I only know from personal experience that by changing the unused area to a transparent or null that it would remove it. This is what seems to be your problem, correct? Give that a shot, then let me know if I helped at all.

tincopper2
  • 79
  • 10
  • That didn't fix my problem, it just changed the black area to the grey. If you want to take a deeper look I can send you my dropbox link for the source – user2976935 Nov 10 '13 at 20:23