Look And Feel getting changed on JDialog - java

I have a swing application, that has its look and feel set to the custom L&F from the company at the main method, where the application is started.
The problem is: This works for ALL frames and windows, but somehow it doesn't work for JDialogs.
I've even manually set the L&F during the initialization of the dialog, but still get the platform dependent L&F.
Looking for answers or bugs that might explain this behavior, I found this thread, that explains that the environment variables change the behavior of the UIManager, so I've set the variables swing.crossplatformlaf and swing.systemlaf to return my custom L&F, but still get the OS dependent L&F.
Is there something that I'm missing here? How can Swing configure a different L&F for just JDialogs? I'm having a different L&F on Linux and Windows because of this.
Any help would be appreciated.

Related

Remove Unexpected border of JTabbedPane

I am trying to add tabs in a JTabbedPane. It is displaying the below mentioned white borderline which I am not expecting here as Every color is already set to Black except the white color for the text colors. What I might be missing.
I am trying to change this class from jitsi project
Here is what I've tried so far.
OS: Ubuntu 19.10: Java Version: 1.8.0_242
Windows 10 Pro: Java Version: 1.8.0_241
I am using default look and feel for this Frame whereas, for my manually created design, it is Nimbus.
The answer for the question heavily depends on the Look and Feel you're using for your application. I can't tell which one you're using by just looking at the screenshot because you modified it a lot and you've left out part of the code in your question that installs it. In case you aren't installing any specific one - you're running the default Look and Feel, which might also be different depending on the OS/JDK versions, if I'm not wrong.
So as #sleepToken already said in the comment - do not post random parts of your code or all of the code, instead post an SSCCE. While sometimes you might think it is unnecessary and/or unrelated - in many cases it is not, and it does help whoever will read and try to answer your question to run the code & debug the issue if necessary.
That being said - I can give a general answer to your question: All component are painted by their respective UI implementation (TabbedPaneUI in this particular case) and in some cases parts of the painting code might not be configurable, for instance some colors or other options might be hard-coded. You can simply look into the source code of the particular UI implementation that your application uses, find the painting code that you want to configure and see if it is actually configurable in the first place.
In case your application uses MetalLookAndFeel - the implementation is MetalTabbedPaneUI. From what I can tell by looking at it's code - it uses colors from TabbedPane.highlight, TabbedPane.borderHightlightColor and TabbedPane.darkShadow UI defaults for the border. Adding custom color for TabbedPane.highlight might fix the issue for you since you didn't mention that you modified that one in your question.
In case it doesn't - I once again recommend posting an SSCCE along with your OS type/version in case you're using a native Look and Feel. Native Look and Feel differs between different JDK versions for different OS version and often uses a highly customized UI implementation that might not be as configurable.

JTextField text is chopped

I am porting an application which was running fine on Gnome 2.x but when moving to Gnome 3.22, the text of some JTextFields are chopped off from the bottom and top.
I am setting the default system LookAndFeel at startup:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
I have tried changing fonts/sizes to match the Gnome 2.x system (Monospace 10) but this doesn't seem to help. I have also tried changing the LookAndFeel to all variations, also without success. I have also tried checking if there are any possible values via gsettings tool but I haven't found any attributes that could influence this.
EDIT:
It appears MadProgrammer guessed correctly, in that the problematic controls are calling setPreferredSize(...), although they are used in conjunction with JGoodies DefaultFormBuilder, GridBagLayout or some other LayoutManager, which I assumed wasn't such "a bad thing"? Disabling this call seems to resolve the issue, however, the formatting is now completely off.
Could there be a UIManager setting for JTextFields which affects this behavior?

Changing LaF based on OS

Im building a GUI in Netbeans, it looks good in the designer but when I run the program it looks pretty rubbish. Im using a Mac and so I feel that it would look better using the Mac OS LAF but then when I run it on Windows, what will happen? Is a Windows system able to use the Mac LAF and vice-versa?
I dont usually mind the Ocean/Metal LAF but it looks better on Windows than it does on Mac, is there a way to set a theme as a fallback? Or to change depending on the system its running on?
The UIManager.setLookAndFeel(String className) Loads the LookAndFeel specified by the given class name:className, using the current thread's context class loader.
To set look and feel of your current system, make use of UIManager.getSystemLookAndFeelClassName(): Returns the name of the LookAndFeel class that implements the native system look and feel if there is one, otherwise the name of the default cross platform LookAndFeel class.
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
put this code before you create instance of your application window: JFrame or any such Top-level Container.

Why in my Java application am I seeing "strange" scrollbars?

In my Java application I have a window which holds a JTextArea within a JScrollPane with scrollbars policies set to AS_NEEDED.
As I run my application I see that JTextArea this way:
Why am I seeing the scrollbars with that cutaway knob (which doesn't reflect a "standard" representation like this)?
The Layout for the frame is GridBagLayout, and I'm on Mac OS X 10.8.2, should that matter.
This is based on the Look and Feel your app is using, and the limitations of Java's integration with the native OS layout components. The one in your screenshot looks like Nimbus.
Swing applications always custom-render the look and feel, and don't do a very good job of using the native OS widgets everywhere. The result is that you get weird looks that might be consistent the OS only some of the time, or only with certain layout components.
Welcome to developing cross-platform desktop apps in Java. :(
To attempt to get the system look and feel when your application starts you can do this:
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassname());
} catch (Exception e) {
// Handle exception
}
This will set the look and feel to that of the system regardless of what you run it on.
And as mentioned, the default look and feel for your application appears to be Nimbus and not OSX's Aqua, which again can be fixed with he above snippet and you could (should you care to) offer a UI option to the user to change the look and feel of the application to whatever they chose.
You are with Nimbus LookAndFeel
http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/nimbus.html

java - adjusting jslider looks on windows laf

been trying this for a while now and can't seem to get it to work. I wrote a little GUI app that uses the OS's default Look And Feel. While I wrote it on linux, it is mainly intended to be used on Windows. The JSliders under linux are fine by me, but on windows the thumbs(sliders? I don't know the right word) become very narrow, and they stop displaying the value above the thumb, too. I thought I could get around this problem with something like this:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UIManager.getLookAndFeelDefaults().put("Slider.thumbWidth", 20);
But, obviously, it doesn't work. How should I do this? seems like it should be a trivial thing, and I already spent more time on it than I'll ever want to admit.
thanks a lot
Not all LAFs will use the UIManager properties.
I'm not aware of the "thumbWidth" property. Maybe you meant to use the "trackWidth"?
Here is a complete list of the UIManager Defaults.

Categories