How can I dynamically alter the Java LAF UIDefaults?
I'm working on cusomizing a Swing application by dynamically altering the UIDefaults. The end goal is to alter many of them (colors, fonts, sizes, borders, etc) and save the result on a per user basis. While it may give the application some non-standard looks, the client asketh and the client shall receive.
The only problem I'm running into is that GUI will only update ONCE. The first time I change a ui property everthing is great, subsequent changes don't affect anything.
// called from the EDT
// uiKeyName points to some ColorUIResource
UIManager.getDefaults().put(uiKeyName, <<color from color picker>>);
SwingUtilties.updateComponentTreeUI(rootWindow);
It works once, but never again. Ideas?
Asked by: Max396 | Posted: 23-01-2022
Answer 1
When you put the new color (for example) in the table, is it a Color object, or a ColorUIResource? As I understand it, the new value will only be taken up if the current value is null
or an instance of UIResource. Thus, if you insert a plain old Color object, any subsequent changes you make will be ignored.
Also, as the linked doc page suggests, this may only help with the font and foreground/background colors; when it comes to changing things like borders and margins, you may be out of luck. This is not what Swing's Pluggable LookAndFeels were designed for. Maybe you could interest the client in a Synth-based LAF?
Answered by: Lily620 | Posted: 24-02-2022Similar questions
Is it possible to "add" to classpath dynamically in java?
java -classpath ../classes;../jar;. parserTester
How can i get the functionality in the above command programmatically? Like, is it possible to run as:
java parserTester
and get the same result? I tried using URLClassLoader but it modifies the classpath and does not add to it.
Thanx!
Thanks for the response Milhous. But that is what i am tryi...
java - How do I dynamically replace the class loader for an Eclipse plug-in?
I am developing an Eclipse plug-in that fits a client-server model. Its a commercial project so we cannot re-distribute the JDBC drivers for the various databases we support with the plug-in.
So I developed a preference page to allow the user locate the jars and have a simple discovery mechanism that iterates through the classes in the jar files, loading each one to verify that it implements the java.sql.Driver int...
java - How do I dynamically access request parameters with JSP EL?
I'm looping through a list of items, and I'd like to get a request parameter based on the item's index.
I could easily do it with a scriptlet as done below, but I'd like to use expression language.
<c:forEach var="item" items="${list}" varStatus="count">
<!-- This would work -->
<%=request.getParameter("item_" + count.index)%>
<!-- I'd like to make this work -->
${param...
java - How to design DAOs when the datasource varies dynamically
Usually when defining a DAO, you would have a setter for the datasource on the DAO object.
My problem is that our datasource varies dynamically based on the request to the server. i.e. every request can access different database instance.
The request holds logical properties, that later can be used to retrieve the connection to the DB of the request.
So when dependency injecting the DAO to the business lo...
dynamic - How could I call Java code dynamically?
How could I write Java code that is executed like javascript code used together with the eval function?
What I would like to achieve would be something like this:
System.execute ("String str = \"test\"; System.out.println(str);");
which would print the word 'test'. (10x dehmann )
A code sample would help a lot.
java - Problem facing while inserting data into dynamically created column of table
I am dynamically adding column to table in db through code using alter table query.
But i am facing problem wen i am trying to insert values in that column. it throws an exception column does not exists.
And wen i clean and rebuild my project through netbeans it works fine.
I am using java and mysql as databse .
Is there any body who know the solution for this problem.
Following is my alter table qu...
Dynamically loading a native library inside Java applet
I am trying to write a Java applet that will read from a user's serial port. For this I am using the Java Comm API in conjuction with the RXTX library. I've successfully managed to read data through a local Java application but I can't seem to do the same from within an applet. The pro...
java - Dynamically refresh JTextArea as processing occurs?
I am trying to create a very simple Swing UI that logs information onto the screen via a JTextArea as processing occurs in the background. When the user clicks a button, I want each call to:
textArea.append(someString + "\n");
to immediately show up in the UI.
At the moment, the JTextArea does not show all log information until the processing has completed after clicking the butto...
java - Dynamically load additional jar files using Web Start / JNLP
The Web Start Developers Guide states
All application resources must be retrieved from the JAR files specified
in the resources section of the JNLP file, or retrieved explicitly
using an HTTP request to the Web server.
Storing resources in JAR files is recom...
java - Can I dynamically unload and reload (other versions of the same) JAR?
I am writing a server program which is used to run unit tests of an API
(displaying lots of information and providing web access to control
/ monitor the whole thing)...
This API is known to the server during compile time and is provided
as a JAR.
To be able to compare between unit test results of different versions
of the API (without restarting the server),
I want ...
Still can't find your answer? Check out these amazing Java communities for help...
Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)