Results 1 to 6 of 6
- 03-14-2010, 07:49 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
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
- 03-14-2010, 08:17 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,144
- Rep Power
- 5
Post your SSCCE showing the problem.
- 03-14-2010, 08:22 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
On the errorText field. I use postcreation code (through properties in Netbeans) to do: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; } }
Java Code:errorText.setVisible(false);
- 03-14-2010, 08:24 PM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,144
- Rep Power
- 5
That is NOT a SSCCE.
- 03-14-2010, 08:31 PM #5
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
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 }
-
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
-
GUI is visible but content is not.
By seemant.bisht in forum AWT / SwingReplies: 3Last Post: 10-07-2009, 06:28 PM -
Text are not visible in GUI
By VinTiger in forum New To JavaReplies: 5Last Post: 05-15-2009, 08:14 AM -
Tab or Table not visible
By madhuvanthi2312 in forum SWT / JFaceReplies: 1Last Post: 04-25-2009, 09:00 AM -
Nodes and edges..making visible and invisible based on distance
By sfaiz in forum Java AppletsReplies: 2Last Post: 04-14-2009, 10:01 PM -
Address bar not visible
By Akashchopra521 in forum New To JavaReplies: 0Last Post: 12-03-2008, 07:13 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks