GridBagLayoutでテーブルを作成しようとしていますが、何が間違っているのか分かりません。GridBagLayoutテーブル
import javax.swing.*;
import java.awt.*;
/**
* Created by 20114283 on 8/21/2016.
*/
public class TableGrid extends JFrame{
JPanel p;
JTextField title;
JTextField t01;
JTextField t02;
JTextField t03;
JTextField t04;
JTextField t05;
JTextField t11;
JTextField t12;
JTextField t13;
JTextField t14;
JTextField t15;
JTextField t21;
JTextField t22;
JTextField t23;
JTextField t24;
JTextField t25;
JTextField t31;
JTextField t32;
JTextField t33;
JTextField t34;
JTextField t35;
public TableGrid(){
createView();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
setTitle("Table");
setSize(new Dimension(700,370));
setLocationRelativeTo(null);
}
private void createView(){
GridBagLayout layout = new GridBagLayout();
layout.columnWidths = new int[] {140,200,180,180};
layout.rowHeights = new int[] {80,100,50,50,50,50};
p = new JPanel(layout);
this.getContentPane().add(p);
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 4;
c.anchor = GridBagConstraints.CENTER;
p.add(title = new JTextField("Cooking Club Members Scores"));
//column 1
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 1;
p.add(t01 = new JTextField(""));
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 1;
p.add(t02 = new JTextField("Beth"));
c.gridx = 0;
c.gridy = 3;
c.gridwidth = 1;
p.add(t03 = new JTextField("Jon"));
c.gridx = 0;
c.gridy = 4;
c.gridwidth = 1;
p.add(t04 = new JTextField("Lupe"));
c.gridx = 0;
c.gridy = 5;
c.gridwidth = 1;
p.add(t05 = new JTextField("Amy"));
//column 2
c.gridx = 1;
c.gridy = 1;
c.gridwidth = 1;
p.add(t11 = new JTextField("Appetizer"));
c.gridx = 1;
c.gridy = 2;
c.gridwidth = 1;
p.add(t12 = new JTextField("25"));
c.gridx = 1;
c.gridy = 3;
c.gridwidth = 1;
p.add(t13 = new JTextField("35"));
c.gridx = 1;
c.gridy = 4;
c.gridwidth = 1;
p.add(t14 = new JTextField("20"));
c.gridx = 1;
c.gridy = 5;
c.gridwidth = 1;
p.add(t15 = new JTextField("40"));
//column 3
c.gridx = 2;
c.gridy = 1;
c.gridwidth = 1;
p.add(t21 = new JTextField("Main Course"));
c.gridx = 2;
c.gridy = 2;
c.gridwidth = 1;
p.add(t22 = new JTextField("38"));
c.gridx = 2;
c.gridy = 3;
c.gridwidth = 1;
p.add(t23 = new JTextField("29"));
c.gridx = 2;
c.gridy = 4;
c.gridwidth = 1;
p.add(t24 = new JTextField("31"));
c.gridx = 2;
c.gridy = 5;
c.gridwidth = 1;
p.add(t25 = new JTextField("32"));
//column 4
c.gridx = 3;
c.gridy = 1;
c.gridwidth = 1;
p.add(t31 = new JTextField("Dessert"));
c.gridx = 3;
c.gridy = 2;
c.gridwidth = 1;
p.add(t32 = new JTextField("28"));
c.gridx = 3;
c.gridy = 3;
c.gridwidth = 1;
p.add(t33 = new JTextField("37"));
c.gridx = 3;
c.gridy = 4;
c.gridwidth = 1;
p.add(t34 = new JTextField("39"));
c.gridx = 3;
c.gridy = 5;
c.gridwidth = 1;
p.add(t35 = new JTextField("36"));
}
public static void main(String[] args){
new TableGrid();
}
}
ようこそスタックオーバーフロー! [ツアー]を見て回り、[ヘルプ]、特に[*どのように私は良い質問をしますか?*](/助け/やり方)を読んでください。あなたの質問の終わりは役に立たない。あなたが何をしようとしているのか、何を得ているのか、どのように結果が得られていないのかは、有用です。また、サイトがあなたに見せたプレビューとさまざまな書式設定ツールを使用する時間を取ってください。 –