Re: Windows XP Platform L
To: comp.lang.java.gui
Karsten Lentzsch wrote:
Ian Wilson wrote:
[...]
P.S.
JGoodies WindowsLookAndFeel eliminates these problems.
However it does ugly things to JButton sizes (presumably because
JForms handles this) which I have to work around.
The JGoodies Windows L&f uses the native command button margins
by default. You can get wider non-native margins by calling
Options#setUseNarrowButtons(false)
Thanks Karsten,
I have now tried that (see test app [1] below) but didn't see any
difference in the button margins. I've had a quick glance at the Looks
docs but don't yet see where I am going wrong.
If you want to comply with the Windows style guide
you should use the native margins, and ensure a
minimum command button width of 50 Dialog Units.
If I was using JGoodies FormLayout then using DLUs would be easy.
However I have used a mixture of other layout managers and don't relish
the idea of conversion (just yet anyway).
In my real app, to get equal sized buttons, I am doing this:
Dimension buttonSize = (
new JButton("XXXXXXXX")).getPreferredSize();
okButton.setPreferredSize(buttonSize);
cancelButton.setPreferredSize(buttonSize);
This is horrible but will suffice until I find something better, or
until I need to localize the label text, or ... :-)
[1] Test program showing no effect from Options.setUseNarrowButtons(false)
-----------------------------------8<----------------------------------
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerDateModel;
import javax.swing.UIManager;
import com.jgoodies.looks.Options;
import com.jgoodies.looks.windows.WindowsLookAndFeel;
public class TestFonts extends JPanel {
TestFonts() {
add(new JLabel("Lorem Ipsum 21/11/2006"));
add(new JTextField("Foo", 4));
SpinnerDateModel dateModel = new SpinnerDateModel();
JSpinner dateSpinner = new JSpinner(dateModel);
dateSpinner.setEditor(
new JSpinner.DateEditor(dateSpinner, "dd/MM/yyyy"));
add(dateSpinner);
}
private static void createAndShowGUI() {
String antialiasing = "swing.aatext";
if (null == System.getProperty(antialiasing))
System.setProperty(antialiasing, "true");
try {
UIManager.setLookAndFeel(new WindowsLookAndFeel());
} catch (Exception e) {
System.out.println("Unable to set LAF");
}
Options.setUseNarrowButtons(false); // ******************
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame();
frame.setTitle("Testing fonts");
JPanel p = (JPanel) frame.getContentPane();
p.setLayout(new BorderLayout());
p.add(new TestFonts(), BorderLayout.CENTER);
p.add(new ButtonPanel(), BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
class ButtonPanel extends JPanel {
ButtonPanel() {
add(new JButton("OK"));
add(new JButton("Cancel"));
}
}
-----------------------------------8<----------------------------------
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24