Results 1 to 10 of 10
  1. #1
    IYIaster is offline Member
    Join Date
    Jul 2009
    Posts
    46
    Rep Power
    0

    Default Trying to do a simple repaint

    as you guys can tell I'm new to java and I'm trying to do a simple repaint when a change is made to a database. This is not working:

    Java Code:
    NewJFrame.this.removeAll();
    NewJFrame.this.repaint();
    NewJFrame.this.validate();

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

    Default

    Is that all the code you've got?
    What is happening vs what you want to happen?

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

  4. #4
    IYIaster is offline Member
    Join Date
    Jul 2009
    Posts
    46
    Rep Power
    0

    Default

    What other code would you like to see? That code is running when a button is clicked (to make a change to a database) When I click the button the frame freezes

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

    Default

    Show the actionPerformed method code you are running when the button is clicked.

  6. #6
    IYIaster is offline Member
    Join Date
    Jul 2009
    Posts
    46
    Rep Power
    0

    Default

    Here you go

    Java Code:
        private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
            try {
                Class.forName("com.mysql.jdbc.Driver");
                String connectionUrl = "jdbc:mysql://localhost/custsig?" +
                        "user=root&password=";
                Connection con = DriverManager.getConnection(connectionUrl);
                jLabel1.setForeground(new java.awt.Color(0, 0, 0));
                jLabel2.setForeground(new java.awt.Color(0, 0, 0));
                jLabel3.setForeground(new java.awt.Color(0, 0, 0));
                jLabel4.setForeground(new java.awt.Color(0, 0, 0));
                newproc = jTextField1.getText();
                newsoft = jTextField2.getText();
                newdeb = jTextField3.getText();
                newcust = jTextField4.getText();
                if (newcust.equals("")) {
                    errorsig1 = 1;
                    jLabel1.setForeground(new java.awt.Color(255, 0, 0));
                } else if (newsoft.equals("")) {
                    errorsig1 = 1;
                    jLabel2.setForeground(new java.awt.Color(0, 0, 0));
                } else if (newproc.equals("")) {
                    errorsig1 = 1;
                    jLabel3.setForeground(new java.awt.Color(0, 0, 0));
                } else if (newdeb.equals("")) {
                    errorsig1 = 1;
                    jLabel4.setForeground(new java.awt.Color(0, 0, 0));
                } else {
                    PreparedStatement ps = con.prepareStatement("UPDATE customer SET cust_name = ? where cust_name = ?");
                    PreparedStatement pssoft = con.prepareStatement("UPDATE customer SET software = ? where cust_name = ?");
                    PreparedStatement psdebit = con.prepareStatement("UPDATE customer SET debit = ? where cust_name = ?");
                    PreparedStatement psproc = con.prepareStatement("UPDATE customer SET processor = ? where cust_name = ?");
    
                    ps.setString(2, newcombo);
                    ps.setString(1, newcust);
                    pssoft.setString(2, newcombo);
                    pssoft.setString(1, newsoft);
                    psdebit.setString(2, newcombo);
                    psdebit.setString(1, newdeb);
                    psproc.setString(2, newcombo);
                    psproc.setString(1, newproc);
                    int rssoft = pssoft.executeUpdate();
                    int rsdebit = psdebit.executeUpdate();
                    int rsproc = psproc.executeUpdate();
                    int rs = ps.executeUpdate();
    
                    NewJFrame.this.removeAllItems();
                    NewJFrame.this.repaint();
                    NewJFrame.this.validate();
                }
            } catch (SQLException eg) {
                System.out.println("SQL Exception: " + eg.toString());
            } catch (ClassNotFoundException cE) {
                System.out.println("Class Not Found Exception: " + cE.toString());
            }
    
    
            if (errorsig1 == 1) {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
                        "Please fill out all boxes.",
                        "Error",
                        JOptionPane.WARNING_MESSAGE);
            }
            jTextField1.setEditable(false);
            jTextField2.setEditable(false);
            jTextField3.setEditable(false);
            jTextField4.setEditable(false);
            jMenuItem1.setEnabled(true);
            jMenuItem4.setEnabled(false);
            jMenuItem6.setEnabled(false);
            jMenuItem3.setEnabled(true);
    
    
        }

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

    Default

    Gawd, I hate looking at code from programs that use NetBeans code generation.

    That being said, I would guess that removeAllItems is a method that is part of your class that subclasses JFrame, that it (again guessing) removes all components from the JFrame. I can't tell for sure as it is not part of the standard Java API.

    I'm guessing that you are trying to show an empty JFrame here. Is it working? Is the JFrame empty?

    One way to display database information in Swing is to display the data in a JTable and then if the data changes, make appropriate changes to the JTable's model. I'm not sure if this would work for you.

  8. #8
    IYIaster is offline Member
    Join Date
    Jul 2009
    Posts
    46
    Rep Power
    0

    Default

    Thank you I will give that a try also don't hate on netbeans it's awesome!

  9. #9
    IYIaster is offline Member
    Join Date
    Jul 2009
    Posts
    46
    Rep Power
    0

    Default

    I really didn't want to do it this way but instead of repainting the jComboBox that I need to update I just cleared the data and reloaded the info from the database it works thanks for your help

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

    Default

    When your app does a database request, does the GUI become non-responsive? If so, you may consider using a SwingWorker to allow you to do your database number-crunching in a background thread.

Similar Threads

  1. Repaint() not working
    By Catkill in forum AWT / Swing
    Replies: 3
    Last Post: 09-09-2009, 10:51 PM
  2. repaint() problems
    By Emily1100125 in forum AWT / Swing
    Replies: 5
    Last Post: 02-03-2009, 04:11 PM
  3. other than paint repaint
    By amith in forum Java 2D
    Replies: 1
    Last Post: 07-01-2008, 11:39 PM
  4. Repaint problem
    By swimberl in forum Java 2D
    Replies: 1
    Last Post: 02-16-2008, 09:12 PM
  5. Repaint problem
    By swimberl in forum Java 2D
    Replies: 0
    Last Post: 01-06-2008, 03: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
  •