我有一個問題,我設置框架的大小,但不起作用。我發現了一個關於這個話題,但它對我沒有幫助...爪哇鞦韆setSize
我試過getContentPane().getSize(500,500)
,但沒有。
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Mere extends JFrame{
private JPanel b;
public Mere(String titlu){
setSize(500,500);
setLayout(null);
this.getSmth();
pack();
show();
}
public void getSmth(){
JLabel user=new JLabel("User");
user.setBounds(10,10,80,25);
getContentPane().add(user);
JTextField userText=new JTextField(20);
userText.setBounds(100,10,160,25);
getContentPane().add(userText);
JPasswordField pas=new JPasswordField(20);
pas.setBounds(100,40,160,25);
getContentPane().add(pas);
JButton n=new JButton("Register");
n.setBounds(180,80,100,30);
getContentPane().add(n);
JLabel pass=new JLabel("Pass");
pass.setBounds(10,40,100,25);
getContentPane().add(pass);
getContentPane().setVisible(true);
}
public static void main(String[]args){
new Mere("yas");
}
}
非常感謝你,我使用null作爲佈局,因爲它更容易。 – Eratys
請記住,容易並不總是正確的,一旦你學會使用佈局管理器,你會發現使用它們更容易 – Frakcool
是的,你有權利。我想我會嘗試GridBagLayout,無論如何感謝提示:D – Eratys