0
我有一个面板,其中包含一个水平框内的框有2个按钮。 现在我扩展这个类,并希望在框的开头添加新的按钮。 我试着addes按钮到盒子的尽头。如何在框布局开始处添加按钮?
任何机构都知道该怎么做呢?
private class MyBoxPanel extends BoxPanel {
public JButton btnPrint;
public MyConfirmationPanel() {
btnPrint = new JButton("print");
add(btnPrint);
add(Box.createRigidArea(new Dimension(5, 0)));
}
protected void confirmActionPerformed(ActionEvent e) {
for (PrinterInputListener listener : listeners)
listener.printConfirmed(printerPanel.getPrint().getId());
}
protected void cancelActionPerformed(ActionEvent e) {
for (PrinterInputListener listener : listeners)
listener.printCancelled();
}
}
>我试图就将此按钮框的末尾。 - 将最后一个JComponent添加到(ZOrder)的末尾,1.您必须getComponentAt(int),2.添加JButton 3.将当前JCmoponet移动到索引+1,4,然后调用revalidate并重新绘制 – mKorbel
你用这个面板创建了一个带有borderlayout的面板,并且设置了2个初始按钮的中心和东部,向西增加了3个? – Fabiotocchi
在MyBoxPanel中,我可以添加任何我想要的东西,但在BoxPanel中,我不允许更改或添加任何东西。 – michdraft