Results 1 to 6 of 6
  1. #1
    dave_gardner is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default Making textTextField's and JPasswordField's Visible on Event

    I have come across what seems like it should be a trivial problem in my project:

    I have set some of my fields on my GUI to invisible (with .setVisible(false);) in post-creation code. When I run the GUI the items are indeed invisible but when I click on my button which has myTextField.setVisible(true); nothing happens. I can get the button to print out something to the terminal everytime I click on it but I can work out how to make the fields appear upon user request.

    Any help is greatly appretiated,

    Regards,

    Dave Gardner
    3rd Year BSc Computer Science, University of Exeter

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    Post your SSCCE showing the problem.

  3. #3
    dave_gardner is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default

    Java Code:
    private void btnStartServerActionPerformed(java.awt.event.ActionEvent evt) {                                               
            
            System.getProperties().setProperty("java.rmi.server.hostname", txtHostname.getText());
            System.out.println("file:/" + txtServerDirectory.getText());
            System.getProperties().setProperty("java.rmi.server.codebase", "file:/" + txtServerDirectory.getText());
    
            String comport = txtComport.getText();
            boolean error = false;
            errorText.setText("");
            errorText.setVisible(false);
    
          
    	    /* Set up server */
    	    SpotlightsServer server = new SpotlightsServer();
                try {
                    server.startController(comport);
                } catch (Exception e) {
                    errorText.setVisible(true);
                    errorText.setText("Cannot Find the Specified COM Port");
                    error = true;
                }
    }
    On the errorText field. I use postcreation code (through properties in Netbeans) to do:

    Java Code:
    errorText.setVisible(false);

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    That is NOT a SSCCE.

  5. #5
    dave_gardner is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default

    Java Code:
    /*
     * TestFrame.java
     *
     * Created on 14-Mar-2010, 19:57:57
     */
    
    //package BackEnd;
    
    /**
     *
     * @author Dave Gardner
     */
    public class TestFrame extends javax.swing.JFrame {
    
        /** Creates new form TestFrame */
        public TestFrame() {
            initComponents();
        }
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
    
            testTextField = new javax.swing.JTextField();
            testTextField.setVisible(false);
            makeVisibleBtn = new javax.swing.JButton();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            testTextField.setText("Test");
    
            makeVisibleBtn.setText("Make Visible");
            makeVisibleBtn.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    makeVisibleBtnActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(158, 158, 158)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(testTextField, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(makeVisibleBtn, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addContainerGap(153, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(74, 74, 74)
                    .addComponent(makeVisibleBtn)
                    .addGap(30, 30, 30)
                    .addComponent(testTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(153, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>
    
        private void makeVisibleBtnActionPerformed(java.awt.event.ActionEvent evt) {
            testTextField.setVisible(true);
        }
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new TestFrame().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify
        private javax.swing.JButton makeVisibleBtn;
        private javax.swing.JTextField testTextField;
        // End of variables declaration
    
    }

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

    Default

    Don't forget to revalidate (and often to repaint) the Container that holds the newly visible component:
    Java Code:
      private void makeVisibleBtnActionPerformed(java.awt.event.ActionEvent evt) {
        testTextField.setVisible(true);
        ((JPanel)getContentPane()).revalidate();
        getContentPane().repaint();
      }

Similar Threads

  1. GUI is visible but content is not.
    By seemant.bisht in forum AWT / Swing
    Replies: 3
    Last Post: 10-07-2009, 06:28 PM
  2. Text are not visible in GUI
    By VinTiger in forum New To Java
    Replies: 5
    Last Post: 05-15-2009, 08:14 AM
  3. Tab or Table not visible
    By madhuvanthi2312 in forum SWT / JFace
    Replies: 1
    Last Post: 04-25-2009, 09:00 AM
  4. Replies: 2
    Last Post: 04-14-2009, 10:01 PM
  5. Address bar not visible
    By Akashchopra521 in forum New To Java
    Replies: 0
    Last Post: 12-03-2008, 07:13 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
  •