yourframename.setSize(frame.getToolkit().getDefaultToolkit().getScreenSize());

解决方案 »

  1.   

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    yourFrame.setBounds(0,0,screenSize.width,screenSize.height);
      

  2.   

    为什么效果 和我使用this.setLocation(0, 0);        一样呢?
      

  3.   

    setBounds(xPos,yPos,width,height)这是其中参数的定义,前面是窗口的位置,以下有段代码,可以稍微修改一下:import javax.swing.*;
    import java.awt.*;public class CentralFrame extends JFrame{
    public CentralFrame(){
    Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((d.width-d.width/2)/2,(d.height-d.height/2)/2,d.width/2,d.height/2);
    setVisible(true);
    }
    public static void main(String[] args){
    CentralFrame frame=new CentralFrame();
    }
    }
      

  4.   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class ClientUser extends JFrame implements ActionListener
    {
    private JPanel contentPane;
    private JPanel jPanel1 = new JPanel();
    private JPanel jPanel2 = new JPanel();
    private JScrollPane jScrollPane1 = new JScrollPane(); private JMenuBar mnuBar = new JMenuBar();
    private JMenu mnuFile = new JMenu("File");
    private JMenuItem mnuFileQuit = new JMenuItem ("Exit"); private JMenu mnuHelp = new JMenu("Help");
    private JTable jTable1 = new JTable();
    private JComboBox jComboBox1 = new JComboBox();
    private JComboBox jComboBox2 = new JComboBox();
    private JLabel startLabel = new JLabel();
    private JLabel endLabel = new JLabel();
    private JPanel jPanel3 = new JPanel();
    private JTextField ticketText = new JTextField();
    private JLabel orderLabel = new JLabel();
    private BorderLayout borderLayout1 = new BorderLayout();
    private JButton showButton = new JButton();
    private JButton orderButton = new JButton();
    private JButton exitButton = new JButton();
    private GridBagLayout gridBagLayout1 = new GridBagLayout();
    private GridBagLayout gridBagLayout2 = new GridBagLayout();
    private GridBagLayout gridBagLayout3 = new GridBagLayout(); String[]  columnName= {"Flight number", "Origin airport", "Destination airport", "Carrier", "Price", "Day",
    "Time", "Duration","Available seats"};
    QxbirdTableModel tableModel;
    public ClientUser()
    {
    //setSelectStation();
    //setShowTable(); contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);
    this.setSize(new Dimension(800,400));
    this.setTitle("Frame Title");
    jPanel1.setBackground(Color.orange);
    jPanel1.setBorder(BorderFactory.createLoweredBevelBorder());
    jPanel1.setLayout(gridBagLayout3);
    jPanel2.setBackground(Color.orange);
    jPanel2.setBorder(BorderFactory.createLoweredBevelBorder());
    jPanel2.setLayout(gridBagLayout1);
    startLabel.setText("Departure Station");
    endLabel.setText("Destination Station");
    jPanel3.setBackground(Color.orange);
    jPanel3.setBorder(BorderFactory.createEtchedBorder());
    jPanel3.setLayout(gridBagLayout2);
    orderLabel.setText("Order The Ticket  Here");
    showButton.setText("Search");
    orderButton.setText("Order");
    orderButton.addActionListener(this);
    exitButton.setText("Exit System");
    exitButton.addActionListener(this); mnuFileQuit.addActionListener(this);
    mnuFile.add(mnuFileQuit);
    mnuBar.add(mnuFile);
            this.setJMenuBar( mnuBar ); contentPane.add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jScrollPane1,  new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 559, 393));
    contentPane.add(jPanel2, BorderLayout.WEST);
    jPanel2.add(jPanel3,  new GridBagConstraints(0, 5, 1, 1, 1.0, 1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(8, 2, 0, 0), 10, 8));
    jPanel3.add(orderButton,  new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(11, 124, 5, 10), 20, -2));
    jPanel3.add(orderLabel,  new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(21, 76, 0, 10), 11, 18));
    jPanel3.add(ticketText,  new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 64, 0, 10), 143, 0));
    jPanel2.add(startLabel,  new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 116, 0, 8), 9, 9));
    jPanel2.add(endLabel,  new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 104, 0, 12), 9, 9));
    jPanel2.add(jComboBox1,  new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 20, 0, 7), 73, 0));
    jPanel2.add(showButton,  new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(19, 132, 0, 10), 34, -2));
    jPanel2.add(jComboBox2,  new GridBagConstraints(0, 3, 1, 1, 1.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 20, 0, 9), 71, 0));
    jPanel2.add(exitButton,  new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(80, 55, 5, 58), 17, -2)); Dimension screenRect = Toolkit.getDefaultToolkit().getScreenSize();
    int centerWidth = screenRect.width < this.getSize().width ?
    screenRect.width : screenRect.width/2 - this.getSize().width/2;
    int centerHeight = screenRect.height < this.getSize().height ?
     screenRect.height : screenRect.height/2 - this.getSize().height/2; //this.setLocation(centerWidth, centerHeight);
            //contentPane.setLocation(0, 0);
            //contentPane.setSize(jPanel1.getToolkit().getDefaultToolkit().getScreenSize());
            this.setBounds(0,0,screenRect.width,screenRect.height); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.pack();
    this.setVisible(true);
    } public static void main(String[] args)
    {
            ClientUser cu = new ClientUser();
    }
    public void actionPerformed(ActionEvent e)
    {}
    private class QxbirdTableModel extends DefaultTableModel
    {
    QxbirdTableModel(String[] columnName,int columnNo)
    {
    super(columnName,columnNo);
    }
    public boolean isCellEditable(int row, int col)
    {
    return false;
    }
    }
    }
      

  5.   

    to  netwebs(Only Java)  上面的是我的代码 请指正!!!
      

  6.   

    修改如下,在this.pack();后面加上句话就行了,再试this.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    this.setBounds(0,0,screenSize.width,screenSize.height);
      

  7.   

    况且 我的代码内 也有this.pack() 这句话 只是位置稍微靠后而已!
      

  8.   

    在setVisible(true);之后,加上一句:
    setExtendedState(JFrame.MAXIMIZED_BOTH);
      

  9.   

    I服了you,你真懒的可以~~~呵呵
    这50分可不够了,你得再给100分~~
    这是调试好的代码
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class ClientUser extends JFrame implements ActionListener
    {
    private JPanel contentPane;
    private JPanel jPanel1 = new JPanel();
    private JPanel jPanel2 = new JPanel();
    private JScrollPane jScrollPane1 = new JScrollPane(); private JMenuBar mnuBar = new JMenuBar();
    private JMenu mnuFile = new JMenu("File");
    private JMenuItem mnuFileQuit = new JMenuItem ("Exit"); private JMenu mnuHelp = new JMenu("Help");
    private JTable jTable1 = new JTable();
    private JComboBox jComboBox1 = new JComboBox();
    private JComboBox jComboBox2 = new JComboBox();
    private JLabel startLabel = new JLabel();
    private JLabel endLabel = new JLabel();
    private JPanel jPanel3 = new JPanel();
    private JTextField ticketText = new JTextField();
    private JLabel orderLabel = new JLabel();
    private BorderLayout borderLayout1 = new BorderLayout();
    private JButton showButton = new JButton();
    private JButton orderButton = new JButton();
    private JButton exitButton = new JButton();
    private GridBagLayout gridBagLayout1 = new GridBagLayout();
    private GridBagLayout gridBagLayout2 = new GridBagLayout();
    private GridBagLayout gridBagLayout3 = new GridBagLayout(); String[]  columnName= {"Flight number", "Origin airport", "Destination airport", "Carrier", "Price", "Day",
    "Time", "Duration","Available seats"};
    QxbirdTableModel tableModel;
    public ClientUser()
    {
    //setSelectStation();
    //setShowTable(); contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);
    //this.setSize(new Dimension(800,400));
    this.setTitle("Frame Title");
    jPanel1.setBackground(Color.orange);
    jPanel1.setBorder(BorderFactory.createLoweredBevelBorder());
    jPanel1.setLayout(gridBagLayout3);
    jPanel2.setBackground(Color.orange);
    jPanel2.setBorder(BorderFactory.createLoweredBevelBorder());
    jPanel2.setLayout(gridBagLayout1);
    startLabel.setText("Departure Station");
    endLabel.setText("Destination Station");
    jPanel3.setBackground(Color.orange);
    jPanel3.setBorder(BorderFactory.createEtchedBorder());
    jPanel3.setLayout(gridBagLayout2);
    orderLabel.setText("Order The Ticket  Here");
    showButton.setText("Search");
    orderButton.setText("Order");
    orderButton.addActionListener(this);
    exitButton.setText("Exit System");
    exitButton.addActionListener(this); mnuFileQuit.addActionListener(this);
    mnuFile.add(mnuFileQuit);
    mnuBar.add(mnuFile);
            this.setJMenuBar( mnuBar ); contentPane.add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jScrollPane1,  new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 559, 393));
    contentPane.add(jPanel2, BorderLayout.WEST);
    jPanel2.add(jPanel3,  new GridBagConstraints(0, 5, 1, 1, 1.0, 1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(8, 2, 0, 0), 10, 8));
    jPanel3.add(orderButton,  new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(11, 124, 5, 10), 20, -2));
    jPanel3.add(orderLabel,  new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(21, 76, 0, 10), 11, 18));
    jPanel3.add(ticketText,  new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 64, 0, 10), 143, 0));
    jPanel2.add(startLabel,  new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 116, 0, 8), 9, 9));
    jPanel2.add(endLabel,  new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 104, 0, 12), 9, 9));
    jPanel2.add(jComboBox1,  new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 20, 0, 7), 73, 0));
    jPanel2.add(showButton,  new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(19, 132, 0, 10), 34, -2));
    jPanel2.add(jComboBox2,  new GridBagConstraints(0, 3, 1, 1, 1.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 20, 0, 9), 71, 0));
    jPanel2.add(exitButton,  new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(80, 55, 5, 58), 17, -2)); Dimension screenRect = Toolkit.getDefaultToolkit().getScreenSize();
    int centerWidth = screenRect.width < this.getSize().width ?
    screenRect.width : screenRect.width/2 - this.getSize().width/2;
    int centerHeight = screenRect.height < this.getSize().height ?
     screenRect.height : screenRect.height/2 - this.getSize().height/2; //this.setLocation(centerWidth, centerHeight);
            //contentPane.setLocation(0, 0);
            //contentPane.setSize(jPanel1.getToolkit().getDefaultToolkit().getScreenSize());
            this.setBounds(0,0,screenRect.width,screenRect.height); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            this.setBounds(0,0,screenSize.width,screenSize.height); this.setVisible(true);
    } public static void main(String[] args)
    {
            ClientUser cu = new ClientUser();
    }
    public void actionPerformed(ActionEvent e)
    {}
    private class QxbirdTableModel extends DefaultTableModel
    {
    QxbirdTableModel(String[] columnName,int columnNo)
    {
    super(columnName,columnNo);
    }
    public boolean isCellEditable(int row, int col)
    {
    return false;
    }
    }
    }
      

  10.   

    忘了把你原来的代码给去了,其实就是要在
    this.pack();之后再设定窗体的大小,这就是pack()的作用,this.pack()之前的所有窗体大小设定是不管用的。
      

  11.   

    大哥 你的那东西 就那么加上去 能编译过去吗?setExtendedState 是那各类的方法 小人 没见过 或是您打错了?
      

  12.   

    郑重宣布 netwebs(Only Java) 得分!(你们都是江湖我大哥)
      

  13.   

    老大啊,你的代码我一点也没改啊,只是在你的this.pack();这句后面加了下面这两句而已
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    yourFrame.setBounds(0,0,screenSize.width,screenSize.height);
    (可能是复制的时候有问题)
      

  14.   

    I 简直 F 了YOU 
    setExtendedState明明是你自己的你倒来问我~~郁闷
      

  15.   

    虽然结了,还是说清楚吧
    setExtendedState是javax.swing.JFrame实例的方法,参数是javax.swing.JFrame.MAXIMIZED_BOTH