我想列出標籤行中的列。我正在嘗試使用gridbaglayout,但我遇到了問題。當我展開窗口時,它不會展開。這是發生了什麼: GridBag面板不佔用所有的空間
我真正想要的是它的佈局中的單元格佔用1/5的空間,並將標籤轉移到單元格的左側大部分。
public static JPanel createLayout(int rows) {
JPanel product = new JPanel(new GridBagLayout());
String[] lables = {"School", "Advanced #", "Novice #"};
double weight = 1/(lables.length);
for (int i = 0; i < rows; i++) {
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(3, 3, 3, 3);
c.anchor = GridBagConstraints.WEST;
c.gridx = i;
c.weightx = weight;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.NORTHWEST;
for (int j = 0; j < lables.length; j++) {
JLabel l = new JLabel(lables[j]);
product.add(l, c);
}
}
return product;
}
public static void main(String[] args) throws IOException {
JFrame frame = new JFrame("Debate Calculator");
JPanel debates = new JPanel();
frame.add(createLayout(5), BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
使用JTable中...... – MadProgrammer 2013-04-28 21:52:16