I have created one project in netbeans. I have one internal frame, which I want to be displayed as dialog. Please help me. Note:I have used windows look and feel.
Asked
Active
Viewed 3,785 times
-2
-
*"Note:I have used windows look and feel."* Don't do that, set it to [UIManager.getSystemLookAndFeelClassName()](http://docs.oracle.com/javase/7/docs/api/javax/swing/UIManager.html#getSystemLookAndFeelClassName%28%29). Your Linux & OS X users will thank you. – Andrew Thompson Dec 13 '12 at 12:28
2 Answers
5
Don't use a java.awt.Dialog
or javax.swing.JDialog
. Instead look to the JOptionPane
methods that start with 'showInternal..
'. E.G.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
public class InternalDialog {
public static void main(String[] args) throws Exception {
Runnable r = new Runnable() {
@Override
public void run() {
// the GUI as seen by the user (without frame)
JPanel gui = new JPanel(new BorderLayout());
gui.setBorder(new EmptyBorder(2, 3, 2, 3));
JDesktopPane dtp = new JDesktopPane();
gui.add(dtp);
ActionListener listener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Component c= (Component)e.getSource();
JOptionPane.showInternalMessageDialog(c, "Message");
}
};
for (int ii=0; ii<3; ii++) {
JInternalFrame jif = new JInternalFrame();
dtp.add(jif);
jif.setLocation(new Point(ii*30, ii*20));
jif.setSize(200,50);
jif.setVisible(true);
JButton b = new JButton("Click me!");
b.addActionListener(listener);
jif.add(b);
}
// TODO!
gui.setPreferredSize(new Dimension(280, 150));
gui.setBackground(Color.WHITE);
JFrame f = new JFrame("Demo");
f.add(gui);
// Ensures JVM closes after frame(s) closed and
// all non-daemon threads are finished
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// See http://stackoverflow.com/a/7143398/418556 for demo.
f.setLocationByPlatform(true);
// ensures the frame is the minimum size it needs to be
// in order display the components within it
f.pack();
// should be done last, to avoid flickering, moving,
// resizing artifacts.
f.setVisible(true);
}
};
// Swing GUIs should be created and updated on the EDT
// http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html
SwingUtilities.invokeLater(r);
}
}

Andrew Thompson
- 168,117
- 40
- 217
- 433
-
@AndrewThompson, is this the only way? the method `showInputDialog(Component parentComponent, Object message, Object initialSelectionValue)` does not have an internal counterpart. – ryvantage Mar 17 '14 at 19:29
-
@ryvantage (shrugs) I don't use internal frames much. You might look to use [`JOptionPane.showInternalInputDialog(Component,Object,String,int,Icon,Object[],Object)`](http://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html#showInternalInputDialog%28java.awt.Component,%20java.lang.Object,%20java.lang.String,%20int,%20javax.swing.Icon,%20java.lang.Object[],%20java.lang.Object%29) instead.. – Andrew Thompson Mar 18 '14 at 09:16
0
Swing has its own native look and feel. You can document yourself on JDialog
right here. For platform look and feel, try using SWT. Next time please be more specific with your question. Good luck.

Georgian
- 8,795
- 8
- 46
- 87