Results 1 to 4 of 4
  1. #1
    alon2580 is offline Member
    Join Date
    Aug 2008
    Posts
    7
    Rep Power
    0

    Default Jpanel won't refresh

    Hi,
    During an installer that I'm making,I have a panel that ask a user for 4 details(i.e 4 text fields),
    after that action I added a check to see whether all the fields were filled and if not goes back to the custom panel for completion.
    The problem is that once the check fails(i.e not all the fields were filled)and it goes back to the panel, no matter what you type in-it doesn't recognize it and refuse to continue,and check keeps on failing no matter what you do.
    I know its related to refreshing cause even if the user is filling the missing fields and pressing OK the Jpanel isn't catching it.
    I'm using JDK 1.5.012
    I'm also attaching my code.
    10x.

    p.s I also have a fifth field which is editable only when the user checks a check box. I also have problems with it but that is a different story

    Java Code:
    package ****;		 
    import java.awt.*;
    import com.zerog.ia.api.pub.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    
    public class CustomPanel extends CustomCodePanel implements ItemListener
    {
        //Constructor
        public CustomPanel (){
            selected=false;
        }
    private boolean selected;
        private JLabel HostLabel,PortLabel,UsernameLabel1,UsernameLabel2,PasswordLabel1,PasswordLabel2,Caption1,Caption2,Caption3,DomainLabel;
        private Frame frame;
        private JPanel panel;
        private JTextField HostField,PortField,UsernameField1,UsernameField2,field4,DomainNameField;
        private JPasswordField passwordfield1,passwordfield2;
        private JCheckBox check;
        private int i=0;
        GUIAccess gui;
        CustomCodePanelProxy ccpp;
    
    
        public boolean setupUI(CustomCodePanelProxy customCodePanelProxy)
        {
            //set the main panel
            panel=new JPanel();
            panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
            panel.setBackground(new Color(255,255,255));
    
            //Get the frame (window that displays all stuff)
            ccpp = customCodePanelProxy;
            gui = (GUIAccess)customCodePanelProxy.getService(com.zerog.ia.api.pub.GUIAccess.class);
            frame = gui.getFrame();
    
            //put components
    
            //put the first Caption
            Caption1 = new JLabel("<html>Database connection parameters<br></html>");
            Caption1.setFont((Caption1.getFont()).deriveFont(14));
            panel.add(Caption1);
            panel.revalidate();
            panel.repaint();
    
    
            //put the Host label and the HostTextField
            HostLabel = new JLabel("Host:");
            HostLabel.setFont((HostLabel.getFont()).deriveFont(14));
            panel.add(HostLabel);
            panel.revalidate();
            panel.repaint();
            HostField =new JTextField(20);
            HostField.setEditable(true);
            HostField.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
            HostField.setText("localhost");
            panel.add(HostField);
            panel.revalidate();
            panel.repaint();
    
    
            //put the Port label and the PortTextField
            PortLabel = new JLabel("Port:");
            PortLabel.setFont((PortLabel.getFont()).deriveFont(14));
            panel.add(PortLabel);
            panel.revalidate();
            panel.repaint();
            PortField =new JTextField(20);
            PortField.setEditable(true);
            PortField.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
            PortField.setText("3728");
            panel.add(PortField);
            panel.revalidate();
            panel.repaint();
    
    
            //put the second Caption
            Caption2 = new JLabel("User to create tables");
            Caption2.setFont((Caption2.getFont()).deriveFont(14));
            panel.add(Caption2);
            panel.revalidate();
            panel.repaint();
    
    
            //put the Usernamr label and the UsernameTextField
            UsernameLabel1 = new JLabel("User:");
            UsernameLabel1.setFont((UsernameLabel1.getFont()).deriveFont(14));
            panel.add(UsernameLabel1);
            panel.revalidate();
            panel.repaint();
            UsernameField1 =new JTextField(20);
            UsernameField1.setEditable(true);
            UsernameField1.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
            panel.add(UsernameField1);
            panel.revalidate();
            panel.repaint();
    
    
            //put the Password label and the PasswordTextField
            PasswordLabel1 = new JLabel("Password:");
            PasswordLabel1.setFont((PasswordLabel1.getFont()).deriveFont(14));
            panel.add(PasswordLabel1);
            panel.revalidate();
            panel.repaint();
            passwordfield1 =new JPasswordField(20);
            passwordfield1.setEditable(true);
            passwordfield1.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
            panel.add(passwordfield1);
            panel.revalidate();
            panel.repaint();
    
            //adding the CheckBox and the follow TextField
            check = new JCheckBox ("Windows autehntication exist",false);
            check.setBackground(new Color(255,255,255));
            panel.add(check);
            panel.revalidate();
            panel.repaint();
            DomainLabel = new JLabel("Domain");
            DomainLabel.setFont((DomainLabel.getFont()).deriveFont(14));
            panel.add(DomainLabel);
            panel.revalidate();
            panel.repaint();
            DomainNameField =new JTextField(20);
            DomainNameField.setEditable(selected);
            DomainNameField.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
            panel.add(DomainNameField);
            panel.revalidate();
            panel.repaint();
            add(BorderLayout.NORTH,panel);
    
            //Add the listener
            check.addItemListener(this);
    
            return true;	// true if you want your panel displayed or false if not
    Last edited by alon2580; 08-22-2008 at 11:01 AM.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    The code you posted has nothing to do with your validation problems.
    You do need to call revalidate and repaint after adding every component, java will do that for you when the gui is realized.
    For validation try the InputVerifier class. The api comments section has an example of how to use it.

  3. #3
    alon2580 is offline Member
    Join Date
    Aug 2008
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by hardwired View Post
    The code you posted has nothing to do with your validation problems.
    You do need to call revalidate and repaint after adding every component, java will do that for you when the gui is realized.
    For validation try the InputVerifier class. The api comments section has an example of how to use it.
    thanks for the quick reply
    I'm pretty new to Java.
    So I have 2 questions:
    1)Do I or do I not need to call revalidate and repaint?(I didn't understand)
    2)Can you please be more specific about that class?
    Thanks again
    Last edited by alon2580; 08-22-2008 at 11:05 AM. Reason: fixed typo

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    1)Do I or do I not need to call revalidate and repaint?(I didn't understand)
    No, you do not need to call revalidate and repaint during construction, ie, before the gui is realized which happens after a call to either pack or setVisible on its top-level container (eg, JFrame).

    2)Can you please be more specific about that class?
    Lookup the InputVerifier class api in the javadocs and look toward the top of the page in a section of comments/general dicussion about the class and how to use it. There is a short code example showing how to use InputVerifier to insure proper input in a textComponent before shifting focus away from it.

Similar Threads

  1. Avoiding refresh
    By java_srinivasan in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 06-25-2008, 09:01 AM
  2. Can't refresh a JPanel/text
    By nickbeacroft in forum AWT / Swing
    Replies: 8
    Last Post: 06-23-2008, 05:23 PM
  3. refresh JPanel
    By olesja in forum AWT / Swing
    Replies: 1
    Last Post: 04-16-2008, 03:58 PM
  4. How to Refresh the same page by JSP
    By AbuAziz in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 12-10-2007, 04:06 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
  •