模式对话框后面的java工具提示
如何检查这类问题。当我查看桌面应用程序的菜单时,有些菜单显示了关闭按钮的工具提示,该按钮应始终位于最前面。但有些显示在模态对话框的后面
我有点像发这篇文章的人一样的问题:https://coderanch.com/t/460688/java/Glasspanes-tooltips
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
class GlassPaneContent extends JPanel {
GlassPaneContent() {
setSize(200, 50);
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
JButton button = new JButton("A button");
button.setToolTipText("A tooltip");
add(button);
}
}
class GlassPane extends JPanel {
private static final Color BG_COLOR = new Color(0, 0, 0, 96);
private GlassPaneContent content = new GlassPaneContent();
public GlassPane() {
setLayout(null);
setOpaque(false);
add(content);
}
@Override
protected void paintComponent(Graphics g) {
g.setColor(BG_COLOR);
g.fillRect(0, 0, getWidth(), getHeight());
int x = (getWidth() - content.getWidth()) / 2;
int y = (getHeight() - content.getHeight()) / 2;
content.setLocation(x, y);
super.paintComponent(g);
}
}
public class MainWindow extends JFrame {
public MainWindow() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(500, 500);
GlassPane gp = new GlassPane();
getRootPane().setGlassPane(gp);
gp.setVisible(true);
}
public static void main(String[] args) {
new MainWindow().setVisible(true);
}
}
我们正在使用JAVA Swing。如果我需要发布代码,请在下面发表评论。谢谢!
# 1 楼答案
试试这个: