Results 1 to 11 of 11
  1. #1
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default how to set modal to JFrame

    I have JFrame and needs to be set modal ..
    my below codes already made jf as modal .. but jf doesnot have contents of FrmSerial..

    what I missed?

    JFrame jf = new FrmSerial();
    JDialog jd = new JDialog(jf);
    jd.setModal(true);
    jd.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    jd.setLocationByPlatform(false);
    jd.setLocation(location);
    jd.pack();
    jd.setVisible(true);

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by newbiejava View Post
    I have JFrame and needs to be set modal ..
    my below codes already made jf as modal .. but jf doesnot have contents of FrmSerial..

    what I missed?
    You can't set a JFrame to modal, at least not as smoothly as a JDialog which was built for this. Just use a JDialog instead.

  3. #3
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    could you please advise.. how to use JDialog in NetBeans?..
    thanks a lot in advance

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by newbiejava View Post
    could you please advise.. how to use JDialog in NetBeans?..
    thanks a lot in advance
    By reading the tutorial: How to Make Dialogs (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

    and the JDialog API: (I"ll let you look it up).

    Word of advice: It's fine to use NetBeans as an IDE, but don't use NetBeans for Swing code generation, not unless you want to not learn how to code in Swing.

  5. #5
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    hi. thanks for the clue, I tried it .. but I need to show dialog with some labels:

    ie.
    COM Port
    Speed
    Parity
    Databit
    Stopbit

    I am using below codes, but I only able to show label "COM Port" and I dont know how to display another labels and their combo boxes.. as newbie ..I really need your advise

    thanks and regards
    Winanjaya

    Object[] com = {"Select COM","COM1", "COM2", "COM3"};
    Object[] speed = {"Select Speed","1200","2400","4800"};
    Object[] parity = {"Select Parity","None","Even","Mark"}
    Object[] databit = {"Select Databit","8","7"}
    Object[] stopbit = {"Select Databit","1","2"}
    String s = (String)JOptionPane.showInputDialog(
    this,
    "COM Port:",
    "Serial COM Setup Dialog",
    JOptionPane.PLAIN_MESSAGE,
    null,
    com,
    "Select COM");

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Two choices and both involve creating a JPanel with all your labels and what nots. Then you can display the JPanel in the JOptionPane similar to what you have right above, or you can put the JPanel into a JDialog, similar to how you'd put a JPanel into a JFrame -- but with a different constructor. The API will give you the legal JDialog constructors.

    Please don't forget code tags when posting code here.

  7. #7
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    could you please advise, where can I download simple example for this? ..
    many thanks in advance

    Regards

  8. #8
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Open the link that was posted for you above already in reply #4.
    It was posted so that you can open it.

  9. #9
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    still not working.. what I missed?

    Java Code:
    PnlSerial pnlSerial = new PnlSerial();
    JDialog jd = new JDialog();
    jd.add(pnlSerial);
    jd.setModal(true);
    jd.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    jd.setLocationByPlatform(false);
    jd.pack();
    jd.setVisible(true);

  10. #10
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    What did you expect to happen and hapened instead?
    Did you open that link and read the text that appears on the opened page?

  11. #11
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default

    ok, thanks it works already ;>) ..
    thanks for the clue..

    Regards

Similar Threads

  1. How to make a modal JFrame?
    By surot in forum New To Java
    Replies: 20
    Last Post: 06-11-2011, 11:31 PM
  2. How to set Modal to JFrame
    By newbiejava in forum New To Java
    Replies: 3
    Last Post: 02-02-2010, 01:49 PM
  3. Replies: 3
    Last Post: 01-16-2010, 07:14 PM
  4. Extract Simulink modal data to Conqat Library
    By madarapu in forum Eclipse
    Replies: 0
    Last Post: 12-22-2009, 12:07 PM
  5. Can't edit JTextField after modal dialog
    By JavaNerd in forum Java Applets
    Replies: 0
    Last Post: 02-07-2008, 09:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •