Results 1 to 18 of 18

Thread: Open forms

  1. #1
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Open forms

    Hi,

    I have tried a lot of things but I am stuck...

    I have a form with a button. When I click the button a new form is opened.
    When I dispose form 2 I want to do a refresh of the content of form 1.
    Any suggestions on how to do this?

    EDIT:
    I tried a different aproach: Made a jPanel, but I dont get focus. Here is the code:

    Java Code:
    addPanel.setVisible(true);
    addPanel.hasFocus();
    addPanel.getCursor();
    But the main panel still has focus. I can "fix" it if I setVisible(false) , but I dont want this.

    Any suggestions?
    Last edited by asai; 07-31-2012 at 07:09 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default Re: Open forms

    What are the forms?
    Normally you would use a JDialog of some sort, with the parent being a JFrame.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Open forms

    Sorry, I mean Jframe... Not form.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default Re: Open forms

    Then open the second one as a JDialog.
    Then it's all done for you.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Open forms

    The second frame is in its own file. Does it have to be inside the same file?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,814
    Rep Power
    25

    Default Re: Open forms

    Are you referring to classes that you are defining?
    You can put more than one class definition in a file, but its better for maintenance to have one definition per file.
    Only one class in a file can be public and it must have the same name as the file.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Open forms

    Quote Originally Posted by Norm View Post
    Are you referring to classes that you are defining?
    You can put more than one class definition in a file, but its better for maintenance to have one definition per file.
    Only one class in a file can be public and it must have the same name as the file.
    Yes it is like that. I have a class that I want to open from another class. And when I close this class and returns to the first I want to run a refresh on a jTable.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,814
    Rep Power
    25

    Default Re: Open forms

    The description of your problem is confusing.
    I have a class that I want to open from another class
    You don't open a class. You can create an instance of a class and call the class's methods.
    when I close this class and returns to the first
    I don't know what it means to close a class. (except for I/O classes that have a close() method)
    When you call a method in another class, when that method returns the execution goes back to the statement following the call to the method. When the called method returns you could do the refresh.

    Can you try to explain your problem using different terminology?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Open forms

    Sorry for my bad english, but I will try to explain a little better...

    I have a class that displays a window with a table. In this table theres data from a MySQL database table.
    I also have a button and when I click this, it opens a new window:
    Java Code:
    LedgerAddForm ledgerAddForm = new LedgerAddForm();
    ledgerAddForm.setVisible(true);
    In this new window the user can create a new post in the database table.
    There is a save button, and when this is clicked, the post is saved and the window is disposed:
    Java Code:
    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    And it is at this point I would like a refresh on the table in the first window. I have solved this for now with a button:
    Java Code:
    jTable1.setModel(new Classes.LedgerGrid());
    super.repaint();
    It is this action I would like to have run when the new post is saved in the second window.

    Hope this was more clear...

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default Re: Open forms

    So, instead of using a JFrame use a JDialog.

    (Not sure how many times I can say this before you acknowledge it).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Open forms

    Quote Originally Posted by Tolls View Post
    So, instead of using a JFrame use a JDialog.

    (Not sure how many times I can say this before you acknowledge it).
    I am sorry if I seam slow, but that is the reason for posting in the new to java section of the forum...
    Tried with JDialog, but I haven't solved it yet. That is probably bad coding from me.
    So, if anyone has a good documentation with some examples would be great. :)

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default Re: Open forms

    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #13
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Open forms

    Thanks, now it works almost like I want it, but it doesn't repaint the initial frame. I tried to call a repaint on the parent frame from the dialog, but there was an NullPointerException error.

    Heres some of my code:
    Java Code:
    public class LedgerAddForm extends javax.swing.JDialog {
    private LedgerForm lf;
    public LedgerAddForm(JFrame frame, LedgerForm parent) {
    super(frame, true);
    lf = parent;
    and this:
    Java Code:
    lf.frame.repaint();
    this.dispose();
    Any suggestions?
    Last edited by asai; 08-01-2012 at 06:21 PM.

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,814
    Rep Power
    25

    Default Re: Open forms

    there was an NullPointerException error.
    What variable is null? Can you give it a value?
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Open forms

    It has to be the lf.frame.repaint(); that needs a value...
    I commented out this line, and the dialog displays fine, but obviously there is no repaint...

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,814
    Rep Power
    25

    Default Re: Open forms

    It has to be the lf.frame.repaint(); that needs a value...
    Try debugging the code to see what variable is null. Use println statements to print out each variable's value.
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default Re: Open forms

    Quote Originally Posted by asai View Post
    It has to be the lf.frame.repaint(); that needs a value...
    I commented out this line, and the dialog displays fine, but obviously there is no repaint...
    So either lf or lf.frame is null.
    Unless the stack trace shows something in repaint().
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Open forms

    YES! I got it right:
    Java Code:
    super.repaint();
    In the parent frame did the trick.

    Thanks for help. Again, sorry for my crappy english... (And coding)

Similar Threads

  1. Replies: 5
    Last Post: 05-12-2012, 12:00 AM
  2. JSP Forms
    By samcarlsruh in forum New To Java
    Replies: 1
    Last Post: 05-28-2011, 04:57 PM
  3. Different Files Open in File -> Open Workspace
    By mgm2010 in forum JCreator
    Replies: 0
    Last Post: 04-11-2009, 03:14 PM
  4. Replies: 2
    Last Post: 04-28-2008, 11:56 AM
  5. Forms in jsp
    By bbq in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-05-2007, 05:28 AM

Posting Permissions

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