当前位置: 技术问答>java相关
JFrame 怎样改变大小,如何最大化?
来源: 互联网 发布时间:2015-01-29
本文导语: 我的程序如下: 1. ------------------------------------ JFrame frm=new JFrame(); frm.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent we){ System.exit(0); } }); JTextArea jtf=new JTextArea(); jtf.setFont(new Font("宋体",F...
我的程序如下:
1.
------------------------------------
JFrame frm=new JFrame();
frm.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
JTextArea jtf=new JTextArea();
jtf.setFont(new Font("宋体",Font.PLAIN,16));
JScrollPane scroll=new JScrollPane(jtf);
frm.getContentPane().add(scroll,"Center");
frm.setSize(800,600);
frm.validate();
frm.pack();
frm.show();
并不会改变大小
2.
-------------------------------------------------
改为
frm.validate();
frm.pack();
frm.show();
frm.setSize(800,600);
frame是变为满屏,可是JFrame 中的 JScrollPane 不能随着改变大小,
另: JFrame 如何最大化?
1.
------------------------------------
JFrame frm=new JFrame();
frm.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
JTextArea jtf=new JTextArea();
jtf.setFont(new Font("宋体",Font.PLAIN,16));
JScrollPane scroll=new JScrollPane(jtf);
frm.getContentPane().add(scroll,"Center");
frm.setSize(800,600);
frm.validate();
frm.pack();
frm.show();
并不会改变大小
2.
-------------------------------------------------
改为
frm.validate();
frm.pack();
frm.show();
frm.setSize(800,600);
frame是变为满屏,可是JFrame 中的 JScrollPane 不能随着改变大小,
另: JFrame 如何最大化?
|
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test
{
public static void main(String args[])
{
test3();
}
public static void test1()
{
JFrame frm=new JFrame();
frm.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
JTextArea jtf=new JTextArea();
jtf.setFont(new Font("ËÎÌå",Font.PLAIN,16));
JScrollPane scroll=new JScrollPane(jtf);
frm.getContentPane().add(scroll,"Center");
frm.setSize(800,600);
frm.validate();
// frm.pack();
frm.show();
}
public static void test2()
{
JFrame frm=new JFrame();
frm.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
JTextArea jtf=new JTextArea();
jtf.setFont(new Font("ËÎÌå",Font.PLAIN,16));
JScrollPane scroll=new JScrollPane(jtf);
frm.getContentPane().add(scroll,"Center");
// frm.pack();
frm.show();
frm.setSize(800,600);
frm.validate();
}
public static void test3()
{
JFrame frm=new JFrame();
frm.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
JTextArea jtf=new JTextArea();
jtf.setFont(new Font("ËÎÌå",Font.PLAIN,16));
JScrollPane scroll=new JScrollPane(jtf);
frm.getContentPane().add(scroll,"Center");
Dimension dim =Toolkit.getDefaultToolkit().getScreenSize();
frm.setSize(dim);
frm.validate();
frm.show();
}
}
import java.awt.*;
import java.awt.event.*;
public class Test
{
public static void main(String args[])
{
test3();
}
public static void test1()
{
JFrame frm=new JFrame();
frm.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
JTextArea jtf=new JTextArea();
jtf.setFont(new Font("ËÎÌå",Font.PLAIN,16));
JScrollPane scroll=new JScrollPane(jtf);
frm.getContentPane().add(scroll,"Center");
frm.setSize(800,600);
frm.validate();
// frm.pack();
frm.show();
}
public static void test2()
{
JFrame frm=new JFrame();
frm.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
JTextArea jtf=new JTextArea();
jtf.setFont(new Font("ËÎÌå",Font.PLAIN,16));
JScrollPane scroll=new JScrollPane(jtf);
frm.getContentPane().add(scroll,"Center");
// frm.pack();
frm.show();
frm.setSize(800,600);
frm.validate();
}
public static void test3()
{
JFrame frm=new JFrame();
frm.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
JTextArea jtf=new JTextArea();
jtf.setFont(new Font("ËÎÌå",Font.PLAIN,16));
JScrollPane scroll=new JScrollPane(jtf);
frm.getContentPane().add(scroll,"Center");
Dimension dim =Toolkit.getDefaultToolkit().getScreenSize();
frm.setSize(dim);
frm.validate();
frm.show();
}
}