親ウィンドウの中に納まるダイアログボックスを表示するには、JOptionPane.showInternalxxxxxDialogメソッドを呼び出す。MessageDialog, InputDialog の使用例を作ってみた。
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
public class InternalAbout extends JFrame {
public InternalAbout() {
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu(“Help”);
Action aboutAction = new AboutAction();
Action inputAction = new InputAction();
menu.add(inputAction);
menu.add(aboutAction);
menuBar.add(menu);
setJMenuBar(menuBar);
setSize(400, 250);
}
class AboutAction extends AbstractAction {
public AboutAction() {
super(“About”);
}
public void actionPerformed(java.awt.event.ActionEvent ev) {
ImageIcon icon = new ImageIcon(“about.png”);
JOptionPane.showInternalMessageDialog(
getContentPane(),
“About RemoconComponentTest”,
“Title.”,
JOptionPane.PLAIN_MESSAGE,
icon);
}
}
class InputAction extends AbstractAction {
public InputAction() {
super(“Host”);
}
public void actionPerformed(java.awt.event.ActionEvent ev) {
String host = JOptionPane.showInternalInputDialog(
getContentPane(),
“Host:”,
“Please input data”,
JOptionPane.PLAIN_MESSAGE);
System.out.println(host);
}
}
public static void main(String[] args) {
InternalAbout f = new InternalAbout();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}