禁止改变窗体大小以及图标Java
2017-05-20 09:53
686 查看
禁止改变大小
public class ControlFormSize extends JFrame{
public ControlFormSize(){//构造方法
setTitle("设置窗体大小");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭方式
setSize(400,300);
JPanel contentPane=new JPanel();//创建面板对象
contentPane.setLayout(new BorderLayout(0,0));//设置布局
setContentPane(contentPane);//设置内容面班
JLabel label=new JLabel("宽度:400,高度:300");//标签
contentPane.add(label,BorderLayout.CENTER);
JButton b=new JButton("禁值改变窗体大小");
contentPane.add(b,BorderLayout.NORTH);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
do_button_actionPerformed(e);
}
});
}
public void do_button_actionPerformed(ActionEvent e){
setResizable(false);
}
public static void main(String[] args) {
ControlFormSize cf=new ControlFormSize();
cf.setVisible(true);
}
}
图标在窗口显示一个圆形图标
public class DrawIcon implements Icon{
private int width;
private int height;
public int getIconHeight(){
return this.height;
}
public int getIconWidth(){
return this.width;
}
public DrawIcon(int width,int height){
this.width=width;
this.height=height;
}
public void paintIcon(Component arg0,Graphics arg1,int x,int y){
arg1.fillOval(x,y,width,height);//绘制一个圆形
}
public static void main(String[] args) {
DrawIcon icon=new DrawIcon(15,15);
JLabel j=new JLabel("测试",icon,SwingConstants.CENTER);
JFrame jf=new JFrame();
Container c=jf.getContentPane();
j.setIcon(icon);//为标签设置图标
c.add(j);
jf.setSize(250,200);//窗体大小,通过jframe对象实例化
jf.setVisible(true);//窗体显示
}
}
public class ControlFormSize extends JFrame{
public ControlFormSize(){//构造方法
setTitle("设置窗体大小");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭方式
setSize(400,300);
JPanel contentPane=new JPanel();//创建面板对象
contentPane.setLayout(new BorderLayout(0,0));//设置布局
setContentPane(contentPane);//设置内容面班
JLabel label=new JLabel("宽度:400,高度:300");//标签
contentPane.add(label,BorderLayout.CENTER);
JButton b=new JButton("禁值改变窗体大小");
contentPane.add(b,BorderLayout.NORTH);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
do_button_actionPerformed(e);
}
});
}
public void do_button_actionPerformed(ActionEvent e){
setResizable(false);
}
public static void main(String[] args) {
ControlFormSize cf=new ControlFormSize();
cf.setVisible(true);
}
}
图标在窗口显示一个圆形图标
public class DrawIcon implements Icon{
private int width;
private int height;
public int getIconHeight(){
return this.height;
}
public int getIconWidth(){
return this.width;
}
public DrawIcon(int width,int height){
this.width=width;
this.height=height;
}
public void paintIcon(Component arg0,Graphics arg1,int x,int y){
arg1.fillOval(x,y,width,height);//绘制一个圆形
}
public static void main(String[] args) {
DrawIcon icon=new DrawIcon(15,15);
JLabel j=new JLabel("测试",icon,SwingConstants.CENTER);
JFrame jf=new JFrame();
Container c=jf.getContentPane();
j.setIcon(icon);//为标签设置图标
c.add(j);
jf.setSize(250,200);//窗体大小,通过jframe对象实例化
jf.setVisible(true);//窗体显示
}
}
相关文章推荐
- 无边框窗体的拖动以及大小改变的实现方式
- c#禁止通过拖动,双击标题栏改变窗体大小
- vb.net禁止用户改变窗体大小
- 去掉窗体的边框,并且禁止拖动改变窗体大小
- [Win32]只允许最大化最小化窗口,禁止双击标题栏、拖动窗体、点击复原按钮来改变窗口大小
- delphi 程序窗体及控件自适应分辨率(通过ComponentCount遍历改变字体大小以及上下左右)
- 禁止改变窗体的大小
- C#开发WinForm窗体程序时,如何禁止用户改变程序窗体的大小?
- QT5入门之12 - 禁止改变窗体大小
- windows sdk编程禁止改变窗体大小
- java中 实现无标题无边框的窗体能够用鼠标拖动改变窗口大小
- C#的WinForm中如何让窗体大小不能改变
- java改变图片大小
- 哪种布局管理器的容器中的组件大小不随容器大小的变化而改变 .java 高手请进 容器被重新设置大小后
- 动态改变showModalDialog窗体的大小
- 无边框窗体改变大小并移动位置
- Winfrom中怎么设置窗体大小的最小值,用鼠标改变窗体大小时,小到一定程度就小不了了
- C#实现窗体控件随窗体大小改变(包括字体大小)
- delphi里窗体改变大小怎么让里边的TreeView,GroupBox也随着改变大小
- C#实现窗体控件随窗体大小改变(包括字体大小)