わかりません。
私の場合、コンポーネントを動的に追加すると、実行時に ランタイムに追加されます。次の例は、 MigLayout
マネージャでこれを示しています。初めに
package com.zetcode;
import java.awt.event.ActionEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import net.miginfocom.swing.MigLayout;
/*
Demonstrating dynamic addition of labels
with MigLayout manager.
Author: Jan Bodnar
Website: zetcode.com
*/
public class MigLayoutDynamicLabelsEx extends JFrame {
private int counter = 0;
public MigLayoutDynamicLabelsEx() {
initUI();
}
private void initUI() {
MigLayout layout = new MigLayout("wrap 4");
setLayout(layout);
JButton addBtn = new JButton("Add");
addBtn.addActionListener((ActionEvent e) -> {
JLabel lbl = createLabel();
add(lbl, "w 100lp, h 30lp");
pack();
});
add(addBtn);
add(createLabel(), "w 100lp, h 30lp");
add(createLabel(), "w 100lp, h 30lp");
add(createLabel(), "w 100lp, h 30lp");
pack();
setTitle("MigLayout dynamic example");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private JLabel createLabel() {
counter++;
String text = "#table no." + counter;
JLabel lbl = new JLabel(text);
lbl.setBorder(BorderFactory.createEtchedBorder());
return lbl;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
MigLayoutDynamicLabelsEx ex = new MigLayoutDynamicLabelsEx();
ex.setVisible(true);
});
}
}
、ボタンと3つのラベルがあります。ボタンの をクリックすると、レイアウトに新しいラベルが追加されます。 wrap 4
制約 は、1行につき4列を作成します。ウィンドウはpack()
メソッドで再編成されます。
スクリーンショット:あなたが追加した場合
はたぶん、あなたは、人々があなたを助けることが、何を得るのですか。 – Harald