简体   繁体   中英

Change jFrame to jDialog?

I've been trying to change a jFrame to a jDialog so it inherits the icon of the main window but I don't have a clue how to do that. I tried setting it's code from public class jSemestriala extends javax.swing.JFrame to public class jSemestriala extends javax.swing.JDialog but that didn't change the icon of the window. Any ideas? I'm using NetBeans 7.0.1

The JDialog takes its icon from the owner frame. You have two options:

  1. Create an invisible JFrame, set your icon to it and set that frame as owner of the dialog.
  2. Create the Dialog, get the owner, and set the icon to it.

I would choose the first option, it seems saver to me. The second one makes use of the (shared) owner of the dialog. This could cause side effects.

For further reading .

But if you already have an main frame, you simply need to set it as owner in the constructor of the dialog.

You need to specify the "main window" frame as the owner of the JDialog :

// ownerframe is a JFrame;
JFrame ownerframe = new JFrame();
JDialog dlg = new JDialog(ownerframe);

JDialog s have owner frames. The frame is either created for you if you call the constructor new JDialog() , in which case the frame is invisible; or you supply it to the dialog in its constructor using new JDialog(ownerframe) .

  • create a new jdialog

  • hard copy the components from design view of jframe(you can use navigator window to copy all in clearly. ofcourse just copy the components under jframe)

  • paste it on jdialog(again use navigator window . ofcourse paste under jdialog)

  • hard copy the source code from jframe's source code window paste it on jdialog's source code

  • do not touch the automaticly created codes if you need it, add them again by using design window.

  • fix the errors in source code window of new jdialog by using your eyes and hands :)

  • remember all the time: be careful about choosing the type of class form.

sorry for my english.
it could take a long time but it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM