Miglayoutを使用して、パネルの1つにテーブルのようなレイアウトを作成しています。すべてのパネルの幅を200ピクセルに固定する必要があります。パネルにコンポーネントを追加すると、すべて正常に機能しますが、テキストが長い(したがって、表示するのに200ピクセル以上のスペースが必要な)ボタンを挿入しようとすると、ボタンがセルからはみ出し、隣接するボタンと重なります。このコードは私の問題を示しているはずです:
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
/**
* @author Savvas Dalkitsis
*/
public class Test {
public static void main(String[] args) {
JFrame f = new JFrame();
JPanel content = new JPanel(new MigLayout("wrap 5","[200!]","[50!]"));
JButton b = new JButton("Button 1");
content.add(b,"growx");
b = new JButton("Button 2");
content.add(b,"growx");
b = new JButton("Button with a very long text which should not be visible");
content.add(b,"growx");
b = new JButton("Button 4");
content.add(b,"growx");
b = new JButton("Button 5");
content.add(b,"growx");
b = new JButton("Button 6");
content.add(b,"growx");
b = new JButton("Button 7");
content.add(b,"growx");
b = new JButton("Button 8");
content.add(b,"growx");
b = new JButton("Button 9");
content.add(b,"growx");
b = new JButton("Button 10");
content.add(b,"growx");
f.setContentPane(content);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
私が欲しいのは、200ピクセルに収まるすべてのテキストを表示するボタンと、「Buttonwithver...」のような末尾のピリオドです。
これを達成する方法について誰かが考えを持っていますか?
(テストのためにここからmiglayoutを取得できます)