我想作以下阐述:
this proposal: (proposal was edited and code is correct now there)
public class MainFrame extends JFrame {
public static void main(String[] args) {
new MainFrame();
}
public MainFrame() {
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.weightx = 1;
add(new JPanel(), c);
c.gridx = 1;
c.weightx = 0;
c.anchor = GridBagConstraints.CENTER;
add(new JButton("Button"), c);
c.gridx = 2;
c.weightx = 1;
c.anchor = GridBagConstraints.WEST;
add(new JLabel("Label"), c);
pack();
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
但是,它产生以下产出,但纽特吨为核心:

