Change ICEPDF Look And Feel in Java

326 views Asked by At

I am using IcePDF as PDF viewer, with the PropertiesManager I can enable/disable functionalities like for example :

    SwingController controller = new SwingController();

    PropertiesManager properties = new PropertiesManager(System.getProperties(),
            ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE));

    properties.setBoolean(PropertiesManager.PROPERTY_SHOW_UTILITY_PRINT, false);
    properties.setBoolean(PropertiesManager.PROPERTY_SHOW_TOOLBAR_ANNOTATION, false);
    properties.setBoolean(PropertiesManager.PROPERTY_SHOW_UTILITYPANE_ANNOTATION, false);
    properties.setBoolean(PropertiesManager.PROPERTY_SHOW_TOOLBAR_ROTATE, false);
    properties.setBoolean(PropertiesManager.PROPERTY_SHOW_UTILITY_SAVE, false);
    properties.setBoolean(PropertiesManager.PROPERTY_SHOW_TOOLBAR_FIT, false);

    SwingViewBuilder factory = new SwingViewBuilder(controller, properties);

But I want to change the Windows Look And Feel, a simple UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); doesn't work. Can someone have the solution ?

2

There are 2 answers

0
Azrix On BEST ANSWER

I finally just added to the beginning of my code that :

try {
  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
        | UnsupportedLookAndFeelException e) {
  System.err.println("[ err. ] " + e);
}

and it works.

1
pcorless On

The class org.icepdf.ri.viewer.Launcher sets up the look and feel of the Viewer RI which is found in the viewer jar. This is an older class but it still uses the PropertiesManager if you want to override it. You can do with with:

preferences.put("application.lookandfeel", "javax.swing.plaf.metal.MetalLookAndFeel");

This is for ICEpdf 6.3.x but you can uses a similar pattern as your original post if you are on an earlier version. The value can be any valid Look and feel for Swing.