hsi*_*kar 0 java graphics swing jpanel jframe
我已经用Java编程了大约六个月了,并且在JPanels和JFrames中完成了许多与Graphics相关的工作.但最近我遇到了问题.我之前制作的所有JFrame都是setUndecorated(false),但我需要制作一个setUndecorated(true).所以我像往常一样尝试将frame.setUndecorated(true)上述所有frame规格放在上面,所以它看起来像这样:
public static void main(String[] args){
JFrame frame = new JFrame("Frame");
frame.setUndecorated(true);
frame.setSize(600, 800);
frame.setVisible(true);
frame.add(new custompanel());
}
Run Code Online (Sandbox Code Playgroud)
和custompanel班级:
public class custompanel{
public void paintComponent(Graphics g){
g.fillRect(100, 100, 100, 100);
}
}
Run Code Online (Sandbox Code Playgroud)
将g在custompanel不画什么.
但是,如果我删除frame.setUndecorated(true)或更改它将frame.setUndecorated(false)绘制一个矩形.
有什么想法吗?
假设CustomPanel延伸JComponent或JPanel,在添加后使框架可见CustomPanel.调用super.paintComponent(g)绘制任何背景组件都是一个好主意.
frame.setVisible(true);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
794 次 |
| 最近记录: |