gpt4 book ai didi

Java JX浏览器 : Is it possible to draw over the JXBrowser Component?

转载 作者:行者123 更新时间:2023-12-02 05:19:57 25 4
gpt4 key购买 nike

我只是想知道是否可以在 JXBrowser 组件上进行绘制?我在网上搜索了一下,发现使用的BrowserView继承了paintcomponents等。但我似乎无法让它工作。

代码如下:

        public test() {
browser = new Browser();
view = new BrowserView(browser);

JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(view, BorderLayout.CENTER);

test = new JButton("Open FOE");
test.addActionListener(this);
test1 = new JButton("Helpen");
test1.addActionListener(this);
test1.setMaximumSize(new Dimension(90, 20));
JPanel panel1 = new JPanel();
panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));
panel1.add(test);
panel1.add(Box.createRigidArea(new Dimension(0, 15)));
panel1.add(test1);

JPanel panel2 = new JPanel();
panel2.setLayout(new BorderLayout());
panel2.add(panel, BorderLayout.CENTER);
panel2.add(panel1, BorderLayout.EAST);

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(panel2);
frame.setSize(1500, 1000);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

}

现在的样子:

First

我想要实现的目标: Second

最佳答案

使用玻璃板,示例代码片段:

JPanel glassPane = new JPanel()
{
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawString("Test",100,100);
g.setColor(Color.BLUE);
g.drawRect(300,300,300,300);
}
};

glassPane.setOpaque(false);
frame.getGlassPane().setVisible(true);

frame.setGlassPane(glassPane);
frame.setVisible(true);

关于Java JX浏览器 : Is it possible to draw over the JXBrowser Component?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56269807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com