Java on Linux - various lookup classes for root and non-root

I noticed that Java offers different appearance classes for root and non-root users. I am trying to figure out how to make LAF consistent. Moreover, it is incompatible even with the / root user: it depends on how the / root user is registered:

Sample code (compiled and packaged in laf.jar ):

 import javax.swing.UIManager; public class laf { public static void main(java.lang.String[] args) { try { System.out.print(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } } } 

Scenario 1 Logging in (as a graphical user interface) as a regular user

Output Example (as user )

 [ xxx@yyy Downloads]$ java -classpath laf.jar laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel 

Example output (go to root via su )

 [ root@yyy Downloads]# java -classpath ./laf.jar laf javax.swing.plaf.metal.MetalLookAndFeel 

Scenario 2 Logon (in GUI mode) with user rights

Output Example (as root )

 [ root@yyy Downloads]# java -classpath ./laf.jar laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel 

Scenario 3 Logging in via SSH as a regular user (similar to scenario # 1 above, but in this case the same LAF)

Output Example (as user )

 [ xxx@yyy Downloads]$ java -classpath laf.jar laf javax.swing.plaf.metal.MetalLookAndFeel 

Output Example (Go to Root )

 [ root@yyy Downloads]# java -classpath ./laf.jar laf javax.swing.plaf.metal.MetalLookAndFeel 

Software version:

 [ root@yyy Downloads]# java -version java version "1.7.0" Java(TM) SE Runtime Environment (build pxa6470sr9fp10-20150708_01(SR9 FP10)) IBM J9 VM (build 2.6, JRE 1.7.0 Linux amd64-64 Compressed References 20150701_255667 (JIT enabled, AOT enabled) J9VM - R26_Java726_SR9_20150701_0050_B255667 JIT - tr.r11_20150626_95120.01 GC - R26_Java726_SR9_20150701_0050_B255667_CMPRSS J9CL - 20150701_255667) JCL - 20150628_01 based on Oracle jdk7u85-b15 [ root@yyy Downloads]# cat /etc/redhat-release Red Hat Enterprise Linux Workstation release 6.7 (Santiago) 
+5
source share
2 answers

The first line is getSystemLookAndFeelClassName :

 public static String getSystemLookAndFeelClassName() { String systemLAF = AccessController.doPrivileged( new GetPropertyAction("swing.systemlaf")); 

So you can use the user JAVA_OPTS to set

-Dswing.systemlaf=javax.swing.plaf.metal.MetalLookAndFeel

Default.

add this to the .rc -File of the user:

 set JAVA_OPTS=-Dswing.systemlaf=javax.swing.plaf.metal.MetalLookAndFeel export JAVA_OPTS 

Hello

0
source

Source: https://habr.com/ru/post/1236052/


All Articles