views:

46

answers:

1

Hi,

I've decided to have my own custom UI of JToolBar by subclassing BasicToolBarUI, as part of my Swing program.

It works great under OS X (10.6) and Windows (7), but when it comes to Linux, problem occurs:

If the swing component is

  • Using SystemLookAndFeel (With Java LAF it is shown)
  • Using UI BasicToolBarUI (To simplify the problem. With this it already doesn't work)
  • running under Linux (Ubuntu 10.10)

the whole JToolBar doesn't appear anymore.

Can anyone give a hand on this? How to make it appear again on Linux? Thank you in advance.

(I've done the custom UI in order to let user still able to move the toolbar to other edges of the window, but prevent it from going to floating state.)

Cheers,
Shuo


My SSCCE:

// Set the system look and feel:
try { 
 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
 e.printStackTrace();
}

// Create frame
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(200, 100));

// Create toolbar
JToolBar toolbar = new JToolBar(JToolBar.HORIZONTAL);
toolbar.add(new JButton("Foo"));
// With this line toolbar doesn't appear any more (only) on Linux.
toolbar.setUI(new BasicToolBarUI());

// Show UI
panel.add(toolbar);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
A: 

You may not see it because you haven't added anything to it (actions, buttons etc). Empty toolbar usually has height of 1-2 pixels.

UPDATE: From what I can tell by looking at BasicToolBarUI it doesn't really do anything - you have to implement size calculations and painting yourself to get proper results

eugener
in my real program there is a lot of stuff inside :). here for small example, and I did added a JButton "Foo"
zavié
Do you see it if you dont set BasicToolBarUI?
eugener
From what I can tell by looking at BasicToolBarUI it doesn't really do anything - you have to implement size calculations and painting yourself to get proper results
eugener
Yea I see it if I don't set BasicToolBarUI. But it works great (with BasicToolBarUI) on Mac and Windows :/
zavié