[英]JFrame size is too small
i have created a JFrame in netbeans. 我在netbeans中创建了一个JFrame。 But when i run the program, the Jframe size is too small. 但是当我运行程序时,Jframe的大小太小了。 here is my code. 这是我的代码。
import javax.swing.JFrame;
public class Window {
private static void demo()
{
JFrame frame =new JFrame();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable(){
public void run()
{
demo();
}
});
}
}
You can use frame.setSize(width, height)
in order to set its size or frame.setBounds(x, y, width, height)
for setting both the location and size. 您可以使用frame.setSize(width, height)
来设置其大小或frame.setBounds(x, y, width, height)
来设置位置和大小。
A better choice would be to call frame.pack()
after you add some components to its content pane. 更好的选择是在将一些组件添加到其内容窗格后调用frame.pack()
。
Try this way... 试试这种方式......
Use the setSize(width, height)
method of JFrame . 使用JFrame的setSize(width, height)
方法。
public class Myframe extends JFrame{
public Myframe(){
this.setSize(300,300);
}
public static void main(String[] args){
EventQueue.invokeLater(new Runnable(){
public void run(){
Myframe f = new Myframe("Frame");
f.setVisible(true);
}
});
}
}
If you want to maximize it you could try 如果你想最大化它,你可以尝试
this.setVisible(false);
this.setExtendedState(MAXIMIZED_BOTH);
this.setVisible(true);
this.setResizable(false);
Else for some specific size use 否则用于某些特定尺寸的用途
this.setSize(width,height);
You just need to add one line line so that you can give your frame a size.The line is 你只需要添加一个线条,这样你就可以给你的框架一个尺寸。线条是
frame.setSize(300,300);
Here is the full code: 这是完整的代码:
import javax.swing.JFrame;
public class Window {
private static void demo()
{
JFrame frame =new JFrame();
frame.setSize(300,300);
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable(){
public void run()
{
demo();
}
});
}
}
You must have a public component method like 你必须有一个公共组件方法
public gestion_name_of_class() {
initComponents();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.