title: How do I force/get to use GTKLookAndFeel in Java on KDE?
body: <p>First of all, using gnome is not an option (but it is possible to install its libraries).</p>
  
  <p>I need to know what is necessary to display a Java Swing desktop application using the current installed KDE look and feel of KDE. Ideally, the solution should allow me to apply a look and feel that looks like the underlying windowing system (ie: Windows LNF for Windows, GTK LNF for Gnome(GTK), QT LNF for KDE (QT), the default one for other platforms).</p>
  
  <p>Under KDE, you can configure it to use the current KDE theme for GTK applications, too. So, if the solution works with GTK it is fine.</p>
  
  <p>When I run the following piece of code under Gnome (Ubuntu 8.04), the Java application looks beautiful. It integrates very well with the rest of applications:</p>
  
  <pre><code>try {
    // Set System L&amp;F
    UIManager.setLookAndFeel(
    UIManager.getSystemLookAndFeelClassName());
  } catch(Exception e) { //Handle it }
  </code></pre>
  
  <p>However, if I run the same thing under Debian (Lenny) with KDE, the UIManager.getSystemLookAndFeelClassName() call returns the Java default one.
  If I go ahead and force it to use the GTK LNF, the application doesn't work. Some fields are invisible, others become out of place, everything is unusable:</p>
  
  <pre><code>try {
    //Force the GTK LNF on top of KDE, but **it doesn't work**
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
  } catch (Exception e) { /*Handle it*/ }
  </code></pre>
  
  <p>I've also tried to put the following code. It let's the user chose any one of the available LNF and then tries to set it. Metal and Motif work fine. GTK doesn't. The slider is really messed up. The list box looks ugly and disappears, but seems to work. Buttons and menu seem ok. The relevant code is shown here:</p>
  
  <pre><code>(...)
      /** Creates new form SwingFrame */
      public SwingFrame() {
  
      initComponents();
  
      //Save all available lafs in a combobox
      cbLafs.removeAllItems();
      UIManager.LookAndFeelInfo[] lafs=UIManager.getInstalledLookAndFeels();
  
      for (int i=0,t=lafs.length;i&lt;t;i++)
      {
          cbLafs.addItem(lafs[i]);
          System.out.println(lafs[i].getName());
      }
  
      }
  
  public void changeLookAndFeel(String laf)
  {
      //If not specified, get the default one
      if (laf==null) {
      laf=UIManager.getSystemLookAndFeelClassName();
      }
  
          try {
          // Set System L&amp;F
          UIManager.setLookAndFeel(laf);
      }
      catch (Exception e) {
         // handle exception
          e.printStackTrace();
      }
      SwingUtilities.updateComponentTreeUI(this);
  
  }
  
     private void cbLafsActionPerformed(java.awt.event.ActionEvent evt) {                                       
          // TODO add your handling code here:
          UIManager.LookAndFeelInfo laf=(UIManager.LookAndFeelInfo)cbLafs.getSelectedItem();
          if (laf==null)
              changeLookAndFeel(null);
          else
              changeLookAndFeel(laf.getClassName());
      }                                     
  </code></pre>
  
  <p>This same system has all GTK applications working (for example: Firefox) as expected. So:</p>
  
  <p>1) What is missing from the environment to have a Java GTK LNF application working under KDE?</p>
  
  <p>2) What does the JVM checks for to return GTK as the default system theme?</p>
  
  <p>Thanks for you help
  Luis Fernando</p>
  
  <p>PS->I've tried other solutions,too, such as JGoodies, plain AWT and SWT. However, Swing with GTK LNF would be the best solution to avoid the hassle of SWT native libraries and JGoodies extra jars (also, JGoodies LNF doesn't look as integrated as Swing GTK under Gnome). AWT looks hideous (motif-like) and misses lots of features.</p>