Java 实体外观问题
每当我将鼠标悬停在菜单项上时,我会看到一个奇怪的黑色区域,如图所示,我不知道为什么。当我使用系统的外观时,我没有这个问题,所以我认为这是因为物质的外观Java 实体外观问题,java,applet,substance,trident,Java,Applet,Substance,Trident,每当我将鼠标悬停在菜单项上时,我会看到一个奇怪的黑色区域,如图所示,我不知道为什么。当我使用系统的外观时,我没有这个问题,所以我认为这是因为物质的外观 public final class MainFrame extends JFrame { public MainFrame(final Loader loader) { super(Configuration.CLIENT_NAME + " v" + Configuration.getVersion()); try {
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);
}
}
}
我认为删除“c.setBackground(Color.BLACK);”以及所有其他JFrame修改来更改背景颜色,可以通过使背景透明来解决这个问题。就好像黑色区域是顶部JFrame菜单的一部分一样,这看起来像是,我只从个人经验中知道,通过将未使用的区域更改为透明或空,它将删除它。这就是你的问题所在,对吗?试一试,然后让我知道我是否帮了忙。在脚本中的任何地方使用以下代码:
System.setProperty("jgoodies.popupDropShadowEnabled", "false");
或者更准确地说:
UIManager.put("jgoodies.popupDropShadowEnabled", "false");
这并没有解决我的问题,它只是将黑色区域改为灰色。如果您想更深入地了解,我可以向您发送我的dropbox源链接。我认为这是DropShadow处理与半透明/透明窗口的交互较差。可能是视频卡的问题。有没有其他机器可以测试这个?最好是另一家电脑供应商。