簡體   English   中英

物質外觀和感覺小程序問題

[英]Substance lookandfeel applet issue

每當我將鼠標懸停在菜單項上時,都會得到一個奇怪的黑色空間,如圖像中所示,我不確定為什么。 當我使用系統外觀時,我沒有這個問題,所以我認為這是由於外觀和感覺的實質。

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); 
        }
    }
}

在腳本的任何位置使用此代碼:

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

或更正確地說:

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

我認為刪除“ c.setBackground(Color.BLACK);” 以及用於更改背景顏色的所有其他JFrame修改,都可以通過使背景透明來解決此問題。 好像黑色區域是您在頂部的JFrame菜單的一部分一樣,似乎僅憑個人經驗,我知道通過將未使用的區域更改為透明或null可以將其刪除。 這似乎是您的問題,對嗎? 試一試,然后告訴我是否有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM