FaqFormCustomComponentBaselineTroubles

How can I define a baseline rules for my custom component?

If you have a custom component that is a JPanel subclass for example, the NetBeans form editor (aka Matisse), uses just the bottom or top border to align components on the form. Any way, there is a way to informe for Matisse the baseline value, which will be useful for a good GUI design. For example, a simple search panel, where there is a text field where user define a ID that will be searched, and some description will be showed for user at another one. So, to do this component is used just two JTextFields and a JPanel. The image below show the three alignment possibilities on Matisse, top, bottom and baseline:

Image:baseline_FaqFormCustomComponentBaselineTroubles.gif

So, the baseline alignment is possible if you add one of the follow methods on the component:

Simple example:

public int getBaseline( int w, int h ) {
   return h * 3 / 4;
}

An example with an already known component:

public int getBaseline(int w, int h) {
   return Baseline.getBaseline([Known_component], w, h);
}

It is not necessary implements any interface or another artefact, just add this method, which return a distance for baseline alignment since top border. The example above is just a simple example. This behavior is defined on org.jdesktop.layout.Baseline class (see javadoc), and if the custom component is a subclass of a known component, as JButoon and so on, this is not necessary.



  Applies to: NetBeans 5.0, 5.5, 6.x
  Platforms: All
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo