以下のサンプルプログラムは、2つのボタンを持つフレームを表示します。を使用する2番目のボタンを押すとMigLayout
、例外が発生します。を使用する最初のボタンはFlowLayout
問題なく機能します。のバグのようMigLayout
です?
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import net.miginfocom.swing.MigLayout;
public class Main extends JPanel {
static private JFrame frame = new JFrame("Test MigLayout");
public Main() {
JButton flowLayoutButton = new JButton("FlowLayout");
JButton miglayoutButton = new JButton("MigLayout");
add(flowLayoutButton);
add(miglayoutButton);
flowLayoutButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEventIn) {
showDialog(false);
}
});
miglayoutButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEventIn) {
showDialog(true);
}
});
}
public static void main(String[] args) {
Main main = new Main();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(main);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
frame.pack();
frame.setVisible(true);
frame.setBounds(200, 200, 200, 200);
}
});
}
private void showDialog(boolean useMidgLayoutIn) {
JPanel panel = new JPanel(useMidgLayoutIn ? new MigLayout() : new FlowLayout());
JTextArea topTextArea = new JTextArea("Here is some junk text to fill up the Text Area.");
panel.add(topTextArea);
panel.add(new JButton("Button"));
JOptionPane optionPane = new JOptionPane(panel, JOptionPane.ERROR_MESSAGE);
JDialog dialog = optionPane.createDialog(frame, "Application Error");
dialog.setResizable(true);
dialog.pack();
dialog.setVisible(true);
}
}