Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2005

Tip: Looking for answers? Try searching our database.

Tried to follow Java Look and Feel Design Guidelines?

Thread view: 
Dirk Starke - 22 Feb 2005 16:46 GMT
Hello Java-GUI-Developers,

did anyone ever try to develop a Java GUI conforming with Sun's "Java
Look and Feel Design Guidelines"? I receive the impression this is a
hard job. I tried to implement a layout with two radiobuttons with the
below-mentioned code. Somehow the vertical distance between these two
radiobuttons is 11 pixels, not 5 like I intended. Even if I set the
buttons margins to zero I do not reach a 5 pixels distance.
The same problem with checkboxes.

What do I do wrong? Or did Sun's swinging programmers have something
roomier in mind when constructing the metal look and feel?  ;o)

Greetings
   Dirk

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.WindowConstants;

public class RadioButtonExampleGB extends JPanel {
 JRadioButton startAtTopRadioButton = new JRadioButton();
 JRadioButton wrapAroundRadioButton = new JRadioButton();

 public RadioButtonExampleGB() {
   init();
 }

 public static void main(String[] args) {
   RadioButtonExampleGB radioButtonExampleGB = new
RadioButtonExampleGB();
   JFrame frame = new JFrame("RadioButtonExampleGB");
   frame.getContentPane().add(radioButtonExampleGB);
   frame.pack();
   frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
   frame.setVisible(true);
 }

 private void init() {
   setLayout(new GridBagLayout());
   setBackground(Color.blue);

   startAtTopRadioButton.setText("Match Case");
//    startAtTopRadioButton.setMargin(new Insets(0, 0, 0, 0));
   startAtTopRadioButton.setBackground(Color.green);
   wrapAroundRadioButton.setText("Whole Word");
//    wrapAroundRadioButton.setMargin(new Insets(0, 0, 0, 0));
   wrapAroundRadioButton.setBackground(Color.red);

   GridBagConstraints constraints =
     new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                            GridBagConstraints.NORTHWEST,
                            GridBagConstraints.NONE,
                            new Insets(0, 0, 0, 0), 0, 0);

   add(startAtTopRadioButton, constraints);

   constraints.gridy++;
   add(wrapAroundRadioButton, constraints);
 }
}
Thomas Weidenfeller - 23 Feb 2005 09:53 GMT
> Hello Java-GUI-Developers,
>
> did anyone ever try to develop a Java GUI conforming with Sun's "Java
> Look and Feel Design Guidelines"? I receive the impression this is a
> hard job.

GUI development in general is a hard job, often vastly underestimated.

The Sun styleguide does only apply to the Sun PLAF. It is better than
nothing, and not too complex compared to other guides in the field. In
fact, it is too simple in several areas. If the alternatives are to use
Sun's PLAF without any guide, or with Sun's guide, use the guide.
Following it makes things better, although not perfect. If you use a
platform-specific PLAF, follow the styleguide for the particular
platform instead.

> I tried to implement a layout with two radiobuttons with the
> below-mentioned code. Somehow the vertical distance between these two
> radiobuttons is 11 pixels, not 5 like I intended. Even if I set the
> buttons margins to zero,

Don't do this. The distances as described by Sun are additional
distances. If you use GBL, you control them entirely via the Insets.

For non trivial GBL-based layouts you will basically need a
GridBagConstraint with different Insets for each cell in the grid. Your
approach with recycling one GBC might work for your simple example, but
will not scale. The same goes for anchoring, filling, weights, etc. You
will find that many cells need different values.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

Dirk Starke - 24 Feb 2005 10:42 GMT
Hello Thomas,

> > did anyone ever try to develop a Java GUI conforming with Sun's "Java
> > Look and Feel Design Guidelines"? I receive the impression this is a
[quoted text clipped - 9 lines]
> platform-specific PLAF, follow the styleguide for the particular
> platform instead.

Perhaps I should explain the background of my question. I've done GUI
development for several years now. It's not my main job, but part of
it. But whenever I dealt with GridBagLayout I found it difficult to
use. And especially when I wanted to construct an expandable container
it was horrible. That brought me to the idea to implement my own
layout manager, and that's what I did. It works now and I want to
publish it. I was in need of some examples, showing the difference
between GridBagLayout and my layout manager. And I wanted those
examples to be conforming with Sun's styleguide.

> > I tried to implement a layout with two radiobuttons with the
> > below-mentioned code. Somehow the vertical distance between these two
[quoted text clipped - 3 lines]
> Don't do this. The distances as described by Sun are additional
> distances. If you use GBL, you control them entirely via the Insets.

I chose the panel shown in figure 29 of the styleguide as an example
(see http://java.sun.com/products/jlf/ed2/book/HIG.Visual2.html) -- it
seems to be a screenshot. The radiobuttons do not look too narrow. The
distance between the two radiobuttons shown is 5 pixels, you can check
it with M$ Paint. It does not appear that additional insets are meant.
The distance between two radiobuttons without insets is 11 pixels
(without taking the white border into account).

I tried to implement the layout of that container, but had my
problems.
Setting the margins of the radiobuttons to zero was an experiment, but
did not assure success. Believe me, that would not be my first
approach.

> For non trivial GBL-based layouts you will basically need a
> GridBagConstraint with different Insets for each cell in the grid. Your
> approach with recycling one GBC might work for your simple example, but
> will not scale. The same goes for anchoring, filling, weights, etc. You
> will find that many cells need different values.

I tried to show the code as it is shown in Sun's tutorial. With the
constraints class of my layout manager it is easy to reuse the
constraints object.

Greetings
    Dirk


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.