Results 1 to 3 of 3
  1. #1
    Asmicor is offline Member
    Join Date
    Jan 2013
    Rep Power

    Question .setVisible() not working

    Java Code:
    public void mouseClicked(MouseEvent e) {					
    	if (textAddedPlayerName.getText().equals("")) {						
    		long start = System.currentTimeMillis();
    		long current = System.currentTimeMillis();
    		while (current - start < 2000) {
    			current = System.currentTimeMillis();
    	}else {
    		String temp = textAddedPlayerName.getText();
    Whenever I run this code my lblERROR label does not seem to become visible, the timer just starts and runs for the 2 seconds. I read online about repainting but that also did not help.
    lblERROR was added onto a panel if that has something to do with it.

    Also is their a better way to make a timer, as this while loop causes that no other operations can be done by the user, ex he cant type anything in textAddedPlayerName for the 2 seconds.

    PS: I'm just starting to learn Swing , so please be gentle.
    Last edited by Asmicor; 11-29-2013 at 07:57 PM. Reason: Code mistake

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: .setVisible() not working

    Have you tested you mouse event method to see if it is picking up clicks? Have you tested your getText.equals("") code? Do this by
    putting in print statements. Then if that doesn't help, submit an Short, Self Contained, Correct Example that is fully compilable with no syntax errors and ONLY demonstrates the problem at hand. No extraneous code. You be able to demonstrate the problem is less than 50 lines of code.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: .setVisible() not working

    If the setVisible() method is called in code that is using the EDT, nothing will happen to the GUI until the JVM gets control of the EDT back.

    he cant type anything in textAddedPlayerName
    Can it be disabled?
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. What does setVisible() actually do?
    By Prime624 in forum New To Java
    Replies: 14
    Last Post: 04-13-2013, 09:18 PM
  2. SetVisible causing problem
    By eric_bloodaxe in forum NetBeans
    Replies: 2
    Last Post: 03-11-2012, 07:06 PM
  3. setVisible does not work
    By michalss in forum AWT / Swing
    Replies: 5
    Last Post: 04-10-2011, 10:35 PM
  4. .setVisible(false); not working... grr...
    By Roclemir in forum New To Java
    Replies: 8
    Last Post: 05-29-2010, 12:22 AM
  5. can't get setVisible(false) to work
    By alexander.s in forum AWT / Swing
    Replies: 0
    Last Post: 04-27-2010, 08:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts