Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #156 > unrolled thread
| Started by | "Ian Wilson" <ian.wilson@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:25 +0000 |
| Last post | 2011-04-27 15:25 +0000 |
| Articles | 5 — 2 participants |
Back to article view | Back to comp.lang.java.gui
Windows XP Platform Look "Ian Wilson" <ian.wilson@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000
Re: Windows XP Platform L "Karsten Lentzsch" <karsten.lentzsch@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000
Re: Windows XP Platform L "Ian Wilson" <ian.wilson@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000
Re: Windows XP Platform L "Karsten Lentzsch" <karsten.lentzsch@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000
Re: Windows XP Platform L "Ian Wilson" <ian.wilson@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000
| From | "Ian Wilson" <ian.wilson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:25 +0000 |
| Subject | Windows XP Platform Look |
| Message-ID | <daCdneznw9hh6PnYnZ2dnUVZ8sednZ2d@bt.com> |
To: comp.lang.java.gui
I'm trying to get my Swing app to look like a native XP app when run on XP.
In the example below, when run on Windows XP, I find the font used in
the JSpinner is considerably larger than that used in the JTextField and
JLabel.
The main problem is that antialiasing badly affects the clarity of the
digit "2" in the JSpinner.
Is this a common occurrence or am I doing something very unusual?
What do other people do?
---------------------------------8<---------------------------------
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;
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(
UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.out.println("Unable to set LAF");
}
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame();
frame.setTitle("Testing fonts");
frame.getContentPane().add(new TestFonts());
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();
}
});
}
}
---------------------------------8<---------------------------------
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.
---
* 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
[toc] | [next] | [standalone]
| From | "Karsten Lentzsch" <karsten.lentzsch@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:25 +0000 |
| Subject | Re: Windows XP Platform L |
| Message-ID | <ek22c4$hjd$01$1@news.t-online.com> |
| In reply to | #156 |
To: comp.lang.java.gui 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) 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. -Karsten --- * 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
[toc] | [prev] | [next] | [standalone]
| From | "Ian Wilson" <ian.wilson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:25 +0000 |
| Subject | Re: Windows XP Platform L |
| Message-ID | <0t6dnQQq6ZVbLPjYRVnyuw@bt.com> |
| In reply to | #159 |
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
[toc] | [prev] | [next] | [standalone]
| From | "Karsten Lentzsch" <karsten.lentzsch@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:25 +0000 |
| Subject | Re: Windows XP Platform L |
| Message-ID | <ek68js$rfo$03$1@news.t-online.com> |
| In reply to | #160 |
To: comp.lang.java.gui
Ian Wilson wrote:
> 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.
You must configure the options before you set the look&feel.
Move the line "Options.setUseNarrowButtons(false);" up.
> 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 ... :-)
I won't say the above is horrible; it'll scale with
the hardware resolution and font - a good thing.
The width you measure is close to 48 DLU.
But don't use this as preferred size, use it
as minimum size if the layout manager honors that.
-Karsten
---
* 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
[toc] | [prev] | [next] | [standalone]
| From | "Ian Wilson" <ian.wilson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:25 +0000 |
| Subject | Re: Windows XP Platform L |
| Message-ID | <pdKdnQASm9vYXfvYnZ2dnUVZ8s2dnZ2d@bt.com> |
| In reply to | #168 |
To: comp.lang.java.gui
Karsten Lentzsch wrote:
> Ian Wilson wrote:
>
>> 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.
>
>
> You must configure the options before you set the look&feel.
> Move the line "Options.setUseNarrowButtons(false);" up.
>
Thanks Karsten, I can now see the effect.
>> 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 ... :-)
>
>
> I won't say the above is horrible; it'll scale with
> the hardware resolution and font - a good thing.
> The width you measure is close to 48 DLU.
> But don't use this as preferred size, use it
> as minimum size if the layout manager honors that.
I find it interesting that, by default, JButtons have minimumSize =
preferredSize = maximumSize.
My superficial testing yesterday suggested that BoxLayout sizes buttons
to their maximumSize, FlowLayout sizes buttons to their preferredSize
and GridLayout ignores everything (happily making buttons bigger than
their maximumSize). GridBag, of course, is more complicated :-)
I'll do more testing with minimumSize - thanks for the tips (and of
course for JGoodies Looks etc)
---
* 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web