0

I have a Java Swing app that I'm writing, that connects to my minecraft server and acts as administrative aid. It has a JList object in one of its panes that keeps track of which players are online. This is how I update the list:

public static void updatePlayerList(HashMap<String,String> players){
    playerListModel.clear(); //this is a DefaultListModel
    playerListModel.setSize(players.size());
    Object[] playerArray = players.keySet().toArray();
    for(int i = 0; i<players.size(); i++){
        playerListModel.set(i, playerArray[i]);
    }

This works fine and dandy and I personally have zero issue with it on my PC. However, two of my moderators are having issues with it forcing focus, even away from other applications.

I'd prefer that it didnt force focus from other applications, Is there any way to prevent this JList from doing that?

CorrieKay
  • 181
  • 1
  • 4
  • 15
  • 1
    It seems very unlikely that this code is your culprit. How have you deduced it to be? – Ricky Clarkson Oct 13 '12 at 01:14
  • 1
    For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Oct 13 '12 at 01:15
  • 1
    I'd be searching for references to `requestFocus` in you code and see if any are released to the change in the model, include changes in the selections – MadProgrammer Oct 13 '12 at 01:23
  • @RickyClarkson: i incorrectly deduced it to be this, because this is the only code that runs when players are being updated. My moderators have told me they guarentee this is when it happens. – CorrieKay Oct 13 '12 at 01:40
  • @AndrewThompson: I wrote an SSCCE and had my moderators run the code, cannot reproduce. However, read above, and below. – CorrieKay Oct 13 '12 at 01:41
  • @MadProgrammer: I checked every single .java file in my project, there are no requestFocus() calls. – CorrieKay Oct 13 '12 at 01:42
  • 1
    *"My moderators have told me they guarentee"* If the quoted code snippet was in your SSCCE and the mods. experienced the problem in the SSCCE - that supports the point of @RickyClarkson. As an aside, I am very skeptical of people who can 'guarantee' a bug is in particular code, yet have no fix for it, nor can they explain why the snippet causes the behavior. – Andrew Thompson Oct 13 '12 at 01:47
  • i fixed the problem. it was old code firing when the player update packet came in, specifically, setting the JFrame visible however, odd that, running on the same operating systems, we were getting different outcomes... – CorrieKay Oct 13 '12 at 01:59
  • glad you found it :-) BTW: _odd that, running on the same operating systems, we were getting different outcomes_ the exact details of focus behaviour are highly OS dependent.. – kleopatra Oct 13 '12 at 09:46

0 Answers0