每当我将鼠标悬停在菜单项上时,我会看到一个奇怪的黑色空间,如图所示,我不知道为什么。当我使用系统的外观和感觉时,我没有这个问题所以我认为这是因为它的外观和感觉。
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);
}
}
}
答案 0 :(得分:0)
在脚本的任何位置使用此代码:
List<Word> dupeWordList;
dupeWordList = new ArrayList<>(wordList);
dupeWordList.removeAll(Collections.singleton(null));
或更正确:
System.setProperty("jgoodies.popupDropShadowEnabled", "false");
答案 1 :(得分:-1)
我认为删除“c.setBackground(Color.BLACK);”以及改变背景颜色的所有其他JFrame修改,将通过使背景透明来解决这个问题。好像黑色区域是JFrame菜单的一部分,你看起来就好了,我只从个人经验中知道,通过将未使用的区域更改为透明或null,它将删除它。这似乎是你的问题,对吗?试一试,然后让我知道我是否有所帮助。