請有人提供一點見解我的代碼。我想讓天平標籤上的按鈕對齊左上角。我曾嘗試不同的佈局管理器,但似乎都導致在中心Java按鈕佈局rightign
public class DefaultView extends JFrame {
public DefaultView() {
JButton SendBalInc = new JButton();
SendBalInc.setText("Balance");
GridBagConstraints c = new GridBagConstraints();
GridBagLayout gridbag = new GridBagLayout();
c.fill = GridBagConstraints.BOTH;
// Bal.fill = GridBagConstraints.NONE;
JPanel window = new JPanel();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(800, 600);
// this.setUndecorated(true);
window.setBackground(Color.WHITE);
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setBackground(Color.WHITE);
JComponent panel1 = makeTextPanel("Panel #1");
tabbedPane.addTab("PIN ", panel1);
JPanel panel2 = new JPanel();
Box box = Box.createHorizontalBox();
box.add(Box.createHorizontalGlue());
box.add(SendBalInc);
panel2.setBackground(Color.WHITE);
panel2.add(box);
tabbedPane.addTab("Balance", panel2);
JComponent panel3 = makeTextPanel("Panel #3");
tabbedPane.addTab("Dep", panel3);
JComponent panel4 = makeTextPanel("Panel #4");
tabbedPane.addTab("Bill", panel4);
window.setLayout(new GridLayout(1, 2));
window.add(tabbedPane);
this.add(window);
}
protected JComponent makeTextPanel(String text) {
JPanel panel = new JPanel();
panel.setBackground(Color.WHITE);
return panel;
}
}
是不是'新的FlowLayout(的FlowLayout .LEFT)'在JPanel上設置,然後在'BorderLayout'的另一個'JPanel'的'PAGE_START'位置添加它,爲這種情況工作?一個小的工作示例或預期結果的簡單圖表,將非常感謝,從你身邊:-) –