There was a problem with the gadget made before. From time to time, it reported that the array exceeded the boundary, but the specific code could not be located.
Take some time to solve it today.
The effect you want to achieve is like this: multiple threads display messages on the textarea in turn. In order to ensure real-time data update, you need to constantly refresh the textarea component.
The original code is like this
public void refresh() {
if(currentServerName == null) {
//Refuse to refresh
return;
}
setText("");
appendText(LOG_MAP.getOrDefault(currentServerName, ""));
setScrollTop(Double.MAX_VALUE);
}
Directly refresh the data in the textarea in an external thread (a thread created by yourself).
After consulting the data, it is found that the container content must be modified in JavaFX’s own thread to ensure that no error will be reported. So wrap it with the platform. The modified code is as follows:
public void refresh() {
if(currentServerName == null) {
//Refuse to refresh
return;
}
setText("");
appendText(LOG_MAP.getOrDefault(currentServerName, ""));
setScrollTop(Double.MAX_VALUE);
Platform.runLater(()->{
setText("");
appendText(LOG_MAP.getOrDefault(currentServerName, ""));
setScrollTop(Double.MAX_VALUE);
});
}
Read More:
- [Solved] javajdk1.8 Run javaFx Error: Error:Error: A fatal exception has occurred. Unrecognized option: –module-path
- SpringBoot Startup Error: Failed to start component [Connector[HTTP/1.1-8080]]
- [Solved] java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
- [Solved] Hongmeng compiles error: Unable to find the java component with apiVersion 4.
- BeanDefinitionStoreException: Failed to read candidate component class probably due to a new Java
- [Solved] Tomcat7 Start Error: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardCon
- [Solved] Spring set xml Component Scanning error: Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException…
- [Solved] Tomcat Startup Error: A child container failed during start、LifecycleException: Failed to start component
- java.lang.IllegalArgumentException: adding a window to a container
- Redis: How to Implementate LRU Caching Mechanism Manually
- [PROJECT] itdage java to get the weather and send text messages
- Explicit and implicit conversion of Java data type
- Java uses single thread pool to realize multi thread sequential execution (non alternating, non synchronous)
- C language: Implementation of dynamic array initialization, insertion, traversal, deletion and destruction
- [Solved] Java.lang.IllegalStateException: getReader() has already been called for this request
- Three ways of thread sequence alternate execution in Java lock free programming
- Spring cloud Netflix hystrix/acutor/hystrix.stream Error ut005023
- Asynchronous callback case of Java callback function
- How to Solve RAR Files Extract Error with sevenzipjbinding (Multithread Processing)
- Monitoring session to determine whether the user is online or not