当前位置: 技术问答>java相关
请教!!java无边窗口问题
来源: 互联网 发布时间:2015-11-12
本文导语: 小弟是初学者,请问怎样才能做一个没有标题栏(border)的窗口,在vb中很简单,设一下属性(BorderStyle=0)就行了,但在java中我不知怎么做,听说不是用JFrame或Frame,而是用window,但我不知怎么用,还请各位赐教,最好写...
小弟是初学者,请问怎样才能做一个没有标题栏(border)的窗口,在vb中很简单,设一下属性(BorderStyle=0)就行了,但在java中我不知怎么做,听说不是用JFrame或Frame,而是用window,但我不知怎么用,还请各位赐教,最好写一个简单的例子,谢谢!!
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class WindowTest extends JFrame
{
public WindowTest()
{
final JWindow window = new JWindow();
Toolkit toolkit = Toolkit.getDefaultToolkit();
JLabel label = new JLabel(new ImageIcon("images/homelogo.gif"));
label.setBorder(BorderFactory.createLineBorder(Color.black));
window.getContentPane().add(label,BorderLayout.CENTER);
Dimension scmSize = toolkit.getScreenSize();
Dimension labelSize = label.getPreferredSize();
int labelWidth = labelSize.width,labelHeight = labelSize.height;
window.setLocation(scmSize.width/2-(labelWidth/2),scmSize.height/2-(labelHeight/2));
window.pack();
window.show();
window.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
window.dispose();
System.exit(0);
}
});
}
public static void main(String[] args)
{
JFrame frame = new WindowTest();
}
}
希望对你有所帮助!
import java.awt.event.*;
import javax.swing.*;
public class WindowTest extends JFrame
{
public WindowTest()
{
final JWindow window = new JWindow();
Toolkit toolkit = Toolkit.getDefaultToolkit();
JLabel label = new JLabel(new ImageIcon("images/homelogo.gif"));
label.setBorder(BorderFactory.createLineBorder(Color.black));
window.getContentPane().add(label,BorderLayout.CENTER);
Dimension scmSize = toolkit.getScreenSize();
Dimension labelSize = label.getPreferredSize();
int labelWidth = labelSize.width,labelHeight = labelSize.height;
window.setLocation(scmSize.width/2-(labelWidth/2),scmSize.height/2-(labelHeight/2));
window.pack();
window.show();
window.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
window.dispose();
System.exit(0);
}
});
}
public static void main(String[] args)
{
JFrame frame = new WindowTest();
}
}
希望对你有所帮助!
|
你随便找一个有界面的例子,将其中的extends JFrame 换成 extends JWindow就行了。
试试看。
试试看。
|
public class Frame1 extends JWindow
去掉this.setTitle("");
去掉this.setTitle("");
|
javax.swing.JInternalFrame
|
在 JDK 1.4 下 可以用
JFrame.setUndecorated(true);
JFrame.setUndecorated(true);