JPanels> JTabbedPane的> JFrame中。 GridBagContraints Panel不启动NORTHWEST

时间:2017-01-02 19:20:42

标签: java swing layout-manager gridbaglayout

我想去我的tabbedpane panel gridbagconstraints gridx和gridy index start top lef side。但总是从中心开始。我尝试设置框架gridbaglayout和gridbagcontraints锚定西北。仍在中心开始指数。面板索引必须做什么从左上角开始? 有我的秋季课;

package educationManagement.view.admin;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.Spring;
import javax.swing.SpringLayout;

import educationManagement.model.User;

public class AdminMainFrame implements AdminFrame {


    private JFrame frame;
    private JTextField tcNoTextField;
    private JTextField adTextField;
    private JTextField soyAdTextField;
    private JTextField passwordTextField;
    private JButton button;
    private final User user;
    private final String frameTitle; 
    public AdminMainFrame(User user){
        this.user = user;
        frameTitle = "Welcome "  + user.getFirstName() + " " + user.getLastName(); 
        adminMain();
        show();
    }

        private void adminMain() {
        frame = new JFrame(frameTitle);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        {

            {
                JTabbedPane tabbedPane = new JTabbedPane();
                tabbedPane.addTab("Öğrenci Ayarları", getStudentTab());
                tabbedPane.addTab("Ayarlar", getUserTab());
                frame.add(tabbedPane);
            }

        }
        frame.setSize(800, 600); 
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
    }

    public void show() {
        frame.setVisible(true);
    }

    public JPanel getUserTab(){
        JPanel panel = new JPanel();
        GridBagLayout gridBagLayout = new GridBagLayout();
        panel.setLayout(gridBagLayout);

        {

            {
                {
                    JLabel label = new JLabel("Ad :" + user.getFirstName());
                    GridBagConstraints gridBagConstraints = new GridBagConstraints();
                    gridBagConstraints.gridx = 0;
                    gridBagConstraints.gridy = 1;
                    gridBagConstraints.gridwidth = 2;
                    gridBagConstraints.anchor = GridBagConstraints.CENTER;
                    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
                    panel.add(label, gridBagConstraints);
                }

                {
                    JLabel label = new JLabel("Soyad :" + user.getLastName());
                    GridBagConstraints gridBagConstraints = new GridBagConstraints();
                    gridBagConstraints.gridx = 0;
                    gridBagConstraints.gridy = 2;
                    gridBagConstraints.gridwidth = 2;
                    gridBagConstraints.anchor = GridBagConstraints.CENTER;
                    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
                    panel.add(label, gridBagConstraints);
                }

                {
                    button = new JButton("Kimin Ben");
                    button.setActionCommand("Ses");
                    GridBagConstraints gridBagConstraints = new GridBagConstraints();
                    gridBagConstraints.gridx = 0;
                    gridBagConstraints.gridy = 3;
                    gridBagConstraints.gridwidth = 2;
                    gridBagConstraints.anchor = GridBagConstraints.CENTER;
                    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
                    panel.add(button, gridBagConstraints);
                }

            }
            return panel;
        }
    }

    private JPanel getStudentTab(){
        JPanel panel = new JPanel();
        GridBagLayout gridBagLayout = new GridBagLayout();
        panel.setLayout(gridBagLayout);

        {

            {
                {
                    JLabel label = new JLabel("YENİ ÖĞRENCİ EKLE");
                    GridBagConstraints gridBagConstraints = new GridBagConstraints();
                    gridBagConstraints.gridx = 0;
                    gridBagConstraints.gridy = 0;
                    gridBagConstraints.gridwidth = 2;
                    gridBagConstraints.anchor = GridBagConstraints.CENTER;
                    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
                    panel.add(label, gridBagConstraints);
                }
                //Tc No
                {
                    JLabel label = new JLabel("Tc No");
                    GridBagConstraints gridBagConstraints = new GridBagConstraints();
                    gridBagConstraints.gridx = 0;
                    gridBagConstraints.gridy = 1;
                    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
                    panel.add(label, gridBagConstraints);


                    tcNoTextField = new JTextField(20);
                    GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
                    gridBagConstraints2.gridx = 1;
                    gridBagConstraints2.gridy = 1;
                    gridBagConstraints2.insets = new Insets(5, 5, 5, 5);
                    panel.add(tcNoTextField, gridBagConstraints2);
                }

                //Ad

                {
                    JLabel label = new JLabel("Ad");
                    GridBagConstraints gridBagConstraints = new GridBagConstraints();
                    gridBagConstraints.gridx = 0;
                    gridBagConstraints.gridy = 2;
                    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
                    panel.add(label, gridBagConstraints);


                    adTextField = new JTextField(20);
                    GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
                    gridBagConstraints2.gridx = 1;
                    gridBagConstraints2.gridy = 2;
                    gridBagConstraints2.insets = new Insets(5, 5, 5, 5);
                    panel.add(adTextField, gridBagConstraints2);
                }
                //Soyad
                {
                    JLabel label = new JLabel("Soyad");
                    GridBagConstraints gridBagConstraints = new GridBagConstraints();
                    gridBagConstraints.gridx = 0;
                    gridBagConstraints.gridy = 3;
                    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
                    panel.add(label, gridBagConstraints);


                    soyAdTextField = new JTextField(20);
                    GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
                    gridBagConstraints2.gridx = 1;
                    gridBagConstraints2.gridy = 3;
                    gridBagConstraints2.insets = new Insets(5, 5, 5, 5);
                    panel.add(soyAdTextField, gridBagConstraints2);
                }
                //Şifre
                {
                    JLabel label = new JLabel("Şifre");
                    GridBagConstraints gridBagConstraints = new GridBagConstraints();
                    gridBagConstraints.gridx = 0;
                    gridBagConstraints.gridy = 4;
                    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
                    panel.add(label, gridBagConstraints);


                    passwordTextField = new JTextField(20);
                    GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
                    gridBagConstraints2.gridx = 1;
                    gridBagConstraints2.gridy = 4;
                    gridBagConstraints2.insets = new Insets(5, 5, 5, 5);
                    panel.add(passwordTextField, gridBagConstraints2);
                }
                //Dersler
                {
                    JLabel label = new JLabel("Dersler");
                    GridBagConstraints gridBagConstraints = new GridBagConstraints();
                    gridBagConstraints.gridx = 0;
                    gridBagConstraints.gridy = 5;
                    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
                    panel.add(label, gridBagConstraints);


                    JTextField textField = new JTextField(20);
                    GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
                    gridBagConstraints2.gridx = 1;
                    gridBagConstraints2.gridy = 5;
                    gridBagConstraints2.insets = new Insets(5, 5, 5, 5);
                    panel.add(textField, gridBagConstraints2);
                }

            }
            return panel;
        }

    }

    @Override
    public void addStudent() {
        // TODO Auto-generated method stub

    }

    @Override
    public void deleteStudent() {
        // TODO Auto-generated method stub

    }

    @Override
    public void changeStudent() {
        // TODO Auto-generated method stub

    }

    @Override
    public void addTeacher() {
        // TODO Auto-generated method stub

    }

    @Override
    public void deleteTeacher() {
        // TODO Auto-generated method stub

    }

    @Override
    public void changeTeacher() {
        // TODO Auto-generated method stub

    }

    @Override
    public void addAdmin() {
        // TODO Auto-generated method stub

    }

    @Override
    public void deleteAdmin() {
        // TODO Auto-generated method stub

    }

    @Override
    public void changeAdmin() {
        // TODO Auto-generated method stub

    }

    @Override
    public void changeSettings() {
        // TODO Auto-generated method stub

    }

    @Override
    public void addButtonListener(ActionListener listener) {
        button.addActionListener(listener);

    }

    public User getUser(){
        return user;
    }
}

0 个答案:

没有答案