i have a problem in changing the icon of a JToggleButton at runtime without clicking this latter or changing its state i've tried to do it with static method but it doesn't change i just wanna know is there a way to do so in java???
this the server
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();
}
}
}
this class handles the clients and it includes the method that change the JToggleButton
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();
}
}
}}
and in final here's the static method i call to change the icon that's situated in MainApp
public static void changeToggleButtonIcon(){
toggleButton.setIcon(new ImageIcon("C:\\Users\\PC-
HOME\\Desktop\\design\\Speech Bubble-50.png"));
}