JWindow上的JPanel,添加组件
我有一个 JFrame
,在 JFrame
代码中我创建了一个 JWindow
,并在窗口上创建了一个 JPanel
。在 JPanel
上插入了背景图像。
JButton btnImage= new JButton("My Button");
Image splashImg = Toolkit.getDefaultToolkit().getImage("images/image1.jpeg");
JPanel pnlSplashWindow= new JPanel(){
public void paint(Graphics g){
g.drawImage(splashImg,0,0,splashImg.getWidth(this),splashImg.getHeight(this),this);
}
};
pnlSplashWindow.setLayout(new BorderLayout());
pnlSplashWindow.add(BorderLayout.SOUTH,btnImage);
JWindo window= new JWindow(this); // this refers to my class which has extended JFrame
window.setContentPane(pnlSplashWindow);
window.setSize(688, 344);
btnImg.setVisible(true);
window.setLocationRelativeTo(this);
我是 JWindow
的新手,有以下问题:
- 如何在
JWindow
(或JPanel
上的JPanel
)上添加按钮和标签等元素代码>JWindow)? - 如何将我的
JFrame
设置为该JWindow
的父级?我的意思是,当JWindow
处于活动状态时,JFrame
不应可单击。
所需最终效果的示例
I have a JFrame
, inside the JFrame
code I create a JWindow
and on window I have created a JPanel
. On JPanel
is inserted a background image.
JButton btnImage= new JButton("My Button");
Image splashImg = Toolkit.getDefaultToolkit().getImage("images/image1.jpeg");
JPanel pnlSplashWindow= new JPanel(){
public void paint(Graphics g){
g.drawImage(splashImg,0,0,splashImg.getWidth(this),splashImg.getHeight(this),this);
}
};
pnlSplashWindow.setLayout(new BorderLayout());
pnlSplashWindow.add(BorderLayout.SOUTH,btnImage);
JWindo window= new JWindow(this); // this refers to my class which has extended JFrame
window.setContentPane(pnlSplashWindow);
window.setSize(688, 344);
btnImg.setVisible(true);
window.setLocationRelativeTo(this);
I am new to JWindow
and have the following questions:
- How to add elements like buttons and labels on
JWindow
(orJPanel
which is on theJWindow
)? - How to set my
JFrame
as the parent of thisJWindow
? I mean whileJWindow
is active, theJFrame
should not be clickable.
An example of the desired end effect
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要添加组件,您应该使用:
代替。如果您不希望 JFrame 可点击,则应使用 modal
JDialog
,通过扩展JDialog
而不是JWindow
。但如果您想创建启动屏幕,您应该阅读如何创建启动屏幕启动画面。
To add components you should use:
instead. And if you don't want your JFrame to be clickable, you should use a modal
JDialog
, by extendingJDialog
instead ofJWindow
.But if you want to create a Splash Screen, you should read How to create a Splash Screen.