Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-21-2008, 07:38 PM
Member
 
Join Date: Aug 2008
Posts: 7
alon2580 is on a distinguished road
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

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 01:01 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-21-2008, 09:08 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-22-2008, 01:04 PM
Member
 
Join Date: Aug 2008
Posts: 7
alon2580 is on a distinguished road
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 01:05 PM. Reason: fixed typo
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-22-2008, 07:26 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Avoiding refresh java_srinivasan JavaServer Pages (JSP) and JSTL 0 06-25-2008 11:01 AM
Can't refresh a JPanel/text nickbeacroft AWT / Swing 8 06-23-2008 07:23 PM
refresh JPanel olesja AWT / Swing 1 04-16-2008 05:58 PM
Refresh Button p_dev_anand Java Blogs 1 01-07-2008 12:25 PM
How to Refresh the same page by JSP AbuAziz JavaServer Pages (JSP) and JSTL 2 12-10-2007 06:06 AM


All times are GMT +3. The time now is 11:55 AM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org