How to paint an invisible JFrame elsewhere?(如何在其他地方绘制不可见的 JFrame?)
问题描述
我想将 JFrame 的内容绘制到另一个框架上.目前,我只有在 JFrame 可见时才能使用它.
有没有办法绘制隐藏的 JFrame?
I want to paint the contents of a JFrame onto another frame. Currently, I only get it to work if the JFrame is visible.
Is there a way to paint a hidden JFrame?
附加信息:
在我的项目中,我需要能够旋转和缩放窗口.我不想编写自己的window-api,所以我想我可能能够以旋转的方式绘制JFrames或类似的容器类(Graphics2D-API很好地支持).能够为此使用标准 JFrame 真是太棒了,但是扩展 JFrame 的自定义框架也可以..
Additional info:
In my project I need to be able to rotate and scale windows. I do not want to write my own window-api, so I thought I might be able to just paint JFrames or similar container classes in a rotated way (which the Graphics2D-API supports perfectly well). It would be awesome to be able to use standard JFrames for that, but a custom frame extending a JFrame would also be OK..
public class JFTest extends JFrame {
private JFrame frameToPaint = null;
public static void main (String[] args) {
new JFTest ();
}
public JFTest () {
// some basic initialization
super ("Container");
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setExtendedState (JFrame.MAXIMIZED_BOTH);
add (new JPanel () {
@Override public void paintComponent (Graphics g) {
super.paintComponent (g);
// painting the child frame's contents onto this frame
if (frameToPaint != null) frameToPaint.getRootPane().paintAll (g);
}
});
setVisible (true);
// initializing some test-frame that will get painted onto the container
frameToPaint = new JFrame ("child");
frameToPaint.setSize (200, 100);
frameToPaint.add (new JLabel ("test"));
frameToPaint.addComponentListener (new ComponentAdapter() {
@Override public void componentResized (ComponentEvent e) { repaint (); }
@Override public void componentHidden (ComponentEvent e) { repaint (); }
});
// magic line. an invisible frame will not get painted! why??
frameToPaint.setVisible (true);
}
}
推荐答案
我想获取框架的图形内容,而不必让用户看到框架
I want to get the graphical contents of a frame without having to make the frame visible for the user
Screen Image 类应该会有所帮助.虽然我认为它只适用于框架的内容窗格"而不是整个框架(带有标题栏和边框),除非您使用装饰框架.
The Screen Image class should help. Although I think it will only work for the "content pane" of the frame and not the entire frame (with the title bar and borders) unless you use a decorated frame.
这篇关于如何在其他地方绘制不可见的 JFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在其他地方绘制不可见的 JFrame?
基础教程推荐
- 存储 20 位数字的数据类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
