动态更改JToggleButton的图标

时间:2017-05-13 15:08:19

标签: java user-interface jtogglebutton

我在运行时更改JToggleButton的图标时遇到问题,而不点击后者或更改其状态 我试过用静态方法做但不会改变 我只想知道在java ???中有没有办法这样做?

这是服务器

ArrayList<String> output=new ArrayList<String>();
for (int i=0; i < letters.size(); i++) {
    output.add(letters.get(i)+" "+Integer.toString(numbers.get(i));
}

}

此类处理客户端,它包含更改JToggleButton

的方法
public class PartsServer {

public static void main(String[] args) {
    try {
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        serverSocketChannel.socket().bind(new InetSocketAddress(6000));
        serverSocketChannel.setOption(SO_RCVBUF, 100);
        boolean running = true;
        while (running) {
            SocketChannel socketChannel
                    = serverSocketChannel.accept();
            new Thread(new ClientHandler(socketChannel)).start();
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }        
}

在最后这里是我调用的静态方法来更改图标 它位于MainApp

package memory;

import java.nio.channels.SocketChannel;

public class ClientHandler implements Runnable{

private final SocketChannel socketChannel;

public ClientHandler(SocketChannel socketChannel) {
    this.socketChannel = socketChannel;
}

public void run() {
    String partName;
    while (true) {
        System.out.println("ani hna");
        partName = HelperMethods.receiveMessage(socketChannel);
        if (partName.equalsIgnoreCase("quit")) {
            break;
        } else {
            MainApp.changeToggleButtonIcon();
        }
    }
}}

}

0 个答案:

没有答案