我有一組按鈕將停留在面板中間。我試圖將它們放置在面板的頂部,使其處於流暢的佈局約束中。任何幫助實現這一點非常感謝。我試過碼頭,但沒有做任何事情。Miglayout將組件對齊到單元格頂部
private class ProductPanel extends JPanel {
private JLabel lblProd;
private JButton butAdd;
private JButton butRemove;
private JButton butEdit;
private Product_Table_Model ptm;
private JScrollPane scroll;
private JPanel buttonPanel;
private JTable table;
ProductPanel() {
setLayout(new MigLayout("debug"));
ptm = new Product_Table_Model(
(ArrayList<Product>) client
.receiveObject("Get_Product_Data"));
initComponents();
}
public void initComponents() {
lblProd = new JLabel ("Product List: ");
buttonPanel = new JPanel (new MigLayout());
butAdd = new JButton ("Add");
butRemove = new JButton ("Remove");
butEdit = new JButton ("Edit");
buttonPanel.add(butAdd, "cell 0 0");
buttonPanel.add(butRemove, "cell 0 1");
buttonPanel.add(butEdit, "cell 0 2");
butAdd.setPreferredSize(new Dimension(40, 50));
add(lblProd, "wrap");
table = new JTable(ptm);
table.setFillsViewportHeight(true);
scroll = new JScrollPane(table);
add(scroll);
add(buttonPanel);
}
}
您需要提供完整的示例。必須有另一個問題;流水模式下的按鈕默認對齊頂部。 –
更新了代碼,試圖做一個圖像,但我沒有10的聲望。 – Grim