I want to customize the jframe and that frame should work like a joptionpane. which is relative with parent. can i do like this. if it is possible please any one help me.
Asked
Active
Viewed 1,979 times
-3
-
1_I want to customize the jframe and make it as a dialog_ Why? Is `JDialog` an option? – BackSlash Sep 17 '13 at 10:05
-
1May you please explain a bit more, as to what is the requirement ? Why to reinvent the wheel ? – nIcE cOw Sep 17 '13 at 10:05
-
i want design a form in a frame and i want to make setopacity,setundecorated,etc..., to that frame but it should work like a joptionpane which means without responding this window we cant touch any window in software. – Tiru Sep 19 '13 at 12:41
2 Answers
3
With a little bit of research, the answer to your question is more accessible than you think.
No use reinventing the wheel. Just use a JDialog
instead of a hacked JFrame
.
Also, please consider putting a little bit more effort in your questions. The quality of answers mirror the quality of the question.

Georgian
- 8,795
- 8
- 46
- 87
-
1My think is that he already know about `JDialog`, i think he wants to reinvent the wheel – BackSlash Sep 17 '13 at 10:09
-
thnk u for ur reply. i want to customize the jframe and that jframe should work as a joptionpane. because i want to design the frame with setundecorated, setOpacity, etc,.... – Tiru Sep 19 '13 at 12:28
1
Below are a few examples of Dialogs with JFrames. Trying to customize a JFrame with a dialog is likely to be very unnecessary as these are just a few from a large range of dialogs you can utilize.
Also as GCrec has referenced, there are the tutorials on Oracle which can give you more of a description.
public class SO {
public static void main(String[] args) {
//Shows a GUI to allow typed input
String showInput = JOptionPane.showInputDialog(new JFrame(), "Enter some input:");
//Shows a GUI displaying a message, in this case the typed input
JOptionPane.showMessageDialog(new JFrame(), showInput);
//A confirmation dialog for choosing yes or no
JOptionPane.showConfirmDialog(new JFrame(), "Was that correct?");
//Options for the below GUI where you have a range of options. The int response
//varies depending on what you select. Then use something like an if statement to react to the input
String[] options = {"Red", "Blue", "Green"};
int response = JOptionPane.showOptionDialog( null, "Favorite Colour?", "Choice?", JOptionPane.YES_NO_OPTION , JOptionPane.PLAIN_MESSAGE , null, options, "Wide Search");
//The one you probably want, the JDialog which is basically a JFrame with a file selection dialog inside
FileDialog fc = new FileDialog(new JFrame(), "File Dialog");
fc.setVisible(true);
String selectedFile = fc.getFile();
System.out.println("You have selected: " + selectedFile);
File f = new File(selectedFile);
JOptionPane.showMessageDialog(new JFrame(), f.getAbsolutePath());
}
Hope this helps! Good luck

Levenal
- 3,796
- 3
- 24
- 29
-
thnk u for ur reply. i want to customize the jframe and that jframe should work as a joptionpane. because i want to design the frame with setundecorated, setOpacity, etc,.... – Tiru Sep 19 '13 at 12:27
-
Sounds like you may want to look into extending JOPtionpane class if you want it to be based from there – Levenal Sep 19 '13 at 12:30
-
i am not sure wat u saying. if i get some examples it will be great. thanks in advance – Tiru Sep 19 '13 at 12:37
-
i want design a form in a frame and i want to make setopacity,setundecorated,etc..., to that frame but it should work like a joptionpane which means without responding this window we cant touch any window in software. – Tiru Sep 19 '13 at 12:42
-
I'm afraid I don't know how to go about such a task. You want to keep the focus on your JFrame like a JOPtion pane. Potentially a solution with a focus listener could be workable, or possibly creating a class which extends the JOPtion pane class, but they would both take a lot of looking into to. – Levenal Sep 19 '13 at 13:23