Results 1 to 9 of 9
  1. #1
    hariza is offline Member
    Join Date
    Aug 2010
    Posts
    24
    Rep Power
    0

    Default refreshing my Buttons after executing an action

    Hi,

    I wonder what do I need to do to refresh my GUI scrollPanes everytime I execute an action. For example I have the code below:

    Java Code:
    purchaseButton.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				if (e.getActionCommand().equals("PURCHASE") && user != null && stationFrom != null && stationTo != null
    						&& startTime != null && endTime != null) {
    
    					 else {
    
    						text.setText("PURCHASE SELECTED");
    						new buyJourneyforUser(user, stationFrom, stationTo, startTime, endTime, n1);
    						userList.setRequestFocusEnabled(false);
    						stationListFrom.setRequestFocusEnabled(true);
    				}	
    				}
    			}
    		});
    Then execute the buyJourneyforUser() but going back to the menu the same selection still on. What do I need to do to reset that back to non-selection. Thanks for your help in advance.

  2. #2
    alinaqvi90 is offline Member
    Join Date
    May 2010
    Posts
    32
    Rep Power
    0

    Default

    perhaps some thing like:

    <your container object>.repaint();
    <your container object>.validate();

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default

    To get better help sooner, post a SSCCE that clearly demonstrates where you have a problem.

    db

  4. #4
    hariza is offline Member
    Join Date
    Aug 2010
    Posts
    24
    Rep Power
    0

    Default

    ok thanks. Actually I tried the repaint and validate but didn't work for me. Also I was hoping that setting the setSelectedIndex(-1) would do the trick but is not working either.

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

    Default

    Quote Originally Posted by hariza View Post
    ok thanks. Actually I tried the repaint and validate but didn't work for me. Also I was hoping that setting the setSelectedIndex(-1) would do the trick but is not working either.
    I like Darryl's idea, creating and posting an SSCCE

  6. #6
    hariza is offline Member
    Join Date
    Aug 2010
    Posts
    24
    Rep Power
    0

    Default

    Hi Again,

    Here below is how I define the listeners :
    Java Code:
    		stationListFrom.addListSelectionListener(new ListSelectionListener() {
    			public void valueChanged(ListSelectionEvent evt) {
    				text.setText("" + stationListFrom.getSelectedValue());
    				stationFrom = text.getText();
    			}
    
    		});
    		stationListTo.addListSelectionListener(new ListSelectionListener() {
    
    			public void valueChanged(ListSelectionEvent evt) {
    				text.setText("" + stationListTo.getSelectedValue());
    				stationTo = text.getText();
    			}
    
    		});
    Then after I pressed the purchase button:
    Java Code:
    purchaseButton.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				while (e.getActionCommand().equals("PURCHASE")) {
    
    					if (n1.Users.get(user).getMytiCredit() == 0) {
    						text.setText("You need to recharge your Myti card first");
    						break;
    					}
    
    	
    					if (e.getActionCommand().equals("PURCHASE") && user != null
    							&& stationListFrom.getSelectedIndex() != -1 && stationListTo.getSelectedIndex() != -1
    							&& HoursListStart.getSelectedIndex() != -1 && MinutesListStart.getSelectedIndex() != -1
    							&& HoursListEnd.getSelectedIndex() != -1 && HoursListEnd.getSelectedIndex() != -1) {
    						text.setText("PURCHASE SELECTED");
    						text.setText(user + stationFrom + stationTo + startTimeHour + endTimeHour);
    						n1.buyJourneyforUser(user, stationFrom, stationTo, startTimeHour, startTimeMinutes,
    								startTimeHourNum, startTimeMinutesNum, endTimeHour, endTimeMinutes, endTimeHourNum,
    								endTimeMinutesNum, n1);
    						stationListFrom.setSelectedIndex(-1);
    						stationListTo.setSelectedIndex(-1);
    						HoursListStart.setSelectedIndex(-1);
    						MinutesListStart.setSelectedIndex(-1);
    						HoursListStart.setSelectedIndex(-1);
    						HoursListEnd.setSelectedIndex(-1);
    						break;
    						// new buyJourneyforUser(user, stationFrom, stationTo,
    						// startTime, endTime, n1);
    						// userList.setRequestFocusEnabled(false);
    						// stationListFrom.setRequestFocusEnabled(true);
    						// cmd="Purchase";
    					} else {
    						text.setText("Please select all the options");
    						break;
    					}
    				}
    			}
    		});

    I was hoping to clear the previous selection otherwise the last sucessfull selection still there.

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

    Default

    Two of us have recommended that you create and post an SSCCE, and yet, nothing. Have you read the link? You might wish to state why you've decided to ignore our advice.

    Best of luck.

  8. #8
    hariza is offline Member
    Join Date
    Aug 2010
    Posts
    24
    Rep Power
    0

    Default

    Sorry for the misunderstanding but I'm not ignoring your recommendations. I thought that part of the code would be good enough. Every recommendation on this forum has been so valuable to me. My Gui class is huge so that is one of the reason's I didn't want to post the whole thing. Thanks!!! :)

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

    Default

    Quote Originally Posted by hariza View Post
    My Gui class is huge so that is one of the reason's I didn't want to post the whole thing.
    And we don't want you to post the whole thing either, and if you read the link, you'll know that.

Similar Threads

  1. Replies: 3
    Last Post: 08-19-2010, 08:27 AM
  2. Replies: 8
    Last Post: 08-10-2010, 02:59 AM
  3. My buttons all perform their action like 100 times
    By 711groove in forum New To Java
    Replies: 0
    Last Post: 12-13-2009, 10:49 AM
  4. JTableHeader not refreshing
    By aznboarder in forum AWT / Swing
    Replies: 4
    Last Post: 04-11-2009, 04:31 AM
  5. Bug in refreshing jsp
    By anki1234 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 12-31-2007, 07:09 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
  •