Results 1 to 4 of 4
Thread: Jpanel won't refresh
- 08-21-2008, 05:38 PM #1
Member
- Join Date
- Aug 2008
- Posts
- 7
- Rep Power
- 0
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 notLast edited by alon2580; 08-22-2008 at 11:01 AM.
- 08-21-2008, 07:08 PM #2
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.
- 08-22-2008, 11:04 AM #3
Member
- Join Date
- Aug 2008
- Posts
- 7
- Rep Power
- 0
Last edited by alon2580; 08-22-2008 at 11:05 AM. Reason: fixed typo
- 08-22-2008, 05:26 PM #4
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
-
Avoiding refresh
By java_srinivasan in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 06-25-2008, 09:01 AM -
Can't refresh a JPanel/text
By nickbeacroft in forum AWT / SwingReplies: 8Last Post: 06-23-2008, 05:23 PM -
refresh JPanel
By olesja in forum AWT / SwingReplies: 1Last Post: 04-16-2008, 03:58 PM -
How to Refresh the same page by JSP
By AbuAziz in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 12-10-2007, 04:06 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks