Laf-Widget - available properties

Client properties


LafWidget. ANIMATION_KIND
since version 1.0

Specifies the speed of the animation effects on a particular component. The value should one of the org.jvnet.lafwidget.utils.AnimationKind enum values and can be set on a component, one of its ancestors or globally on UIManager table. The default value is AnimationKind.REGULAR. Example of creating four buttons with different animation speed:

    JButton bNoAnimation = new JButton("No animation");
    bNoAnimation.putClientProperty(LafWidget.ANIMATION_KIND,
        AnimationKind.NONE);
    JButton bFastAnimation = new JButton("Fast animation");
    bFastAnimation.putClientProperty(LafWidget.ANIMATION_KIND,
        AnimationKind.FAST);
    JButton bRegularAnimation = new JButton("Regular animation");
    bRegularAnimation.putClientProperty(
        LafWidget.ANIMATION_KIND, AnimationKind.REGULAR);
    JButton bSlowAnimation = new JButton("Slow animation");
    bSlowAnimation.putClientProperty(LafWidget.ANIMATION_KIND,
        AnimationKind.SLOW);

LafWidget. COMBO_BOX_USE_MODEL_ONLY
since version 1.0

Specifies that the editable combobox should not allow typing a value that is not present in the combobox model. The value should be either Boolean.TRUE or Boolean.FALSE. At runtime, the value is taken from:
  • The combobox itself.
  • The UIManager table.
If this property is not specified anywhere, the editable combobox allows typing a value that is not present in the combobox model. For example,

    JComboBox comboCompletionModelOnlyTest = new JComboBox(
        new Object[] { "Ester""Jordi""Jordina""Jorge""Sergi" });
    comboCompletionModelOnlyTest.setEditable(true);
    comboCompletionModelOnlyTest.putClientProperty(
        LafWidget.COMBO_BOX_USE_MODEL_ONLY, Boolean.TRUE);


LafWidget. PASSWORD_STRENGTH_CHECKER
since version 1.0

Specifies the custom password strength checker on a JPasswordField. Should be set on the specific JPasswordField. The value should be an instance of a class that implements the org.jvnet.lafwidget.text.PasswordStrengthChecker interface. Sample custom implementation:

jpf.putClientProperty(LafWidget.PASSWORD_STRENGTH_CHECKER,
    new PasswordStrengthChecker() {
      public PasswordStrength getStrength(char[] password) {
        if (password == null)
          return PasswordStrength.WEAK;
        int length = password.length;
        if (length < 3)
          return PasswordStrength.WEAK;
        if (length < 6)
          return PasswordStrength.MEDIUM;
        return PasswordStrength.STRONG;
      }

      public String getDescription(PasswordStrength strength) {
        if (strength == PasswordStrength.WEAK)
          return "<html>This password is <b>way</b> too weak</html>";
        if (strength == PasswordStrength.MEDIUM)
          return "<html>Come on, you can do<br> a little better than that</html>";
        if (strength == PasswordStrength.STRONG)
          return "OK";
        return null;
      }
    });


And the result is:

LafWidget. TABBED_PANE_ PREVIEW_PAINTER
since version 1.0

The org.jvnet.lafwidget.tabbed.TabPreviewPainter class provides an option to have a tab overview button. The org.jvnet.lafwidget.tabbed.DefaultTabPreviewPainter provides a default implementation of this abstract class. In order to set the tab preview painter, use client property LafWidget.TABBED_PANE_PREVIEW_PAINTER on either tabbed pane or globally on UIManager. Value should be an instance of the above class. Once this property is set, the tabbed pane will show an overview button (situated according to the tab placement). Shown below is the tab with tab overview button on TOP and BOTTOM placement:



When the tab overview button is clicked, the tab overview dialog is shown and a separate thread starts populating this dialog with preview thumbnails of all the tab components:



Clicking on a tab thumbnail closes the tab overview dialog and selects the matching tab component. Basic rollover effects and tooltip messages are provided on the tab overview widgets.

In addition, this property can enable a tab preview window that will be shown when the mouse hovers over a tab. The tabbed pane will show preview window of the tab under mouse (aligned according to the tab placement):



The screenshots above are from a tabbed pane that has the client property set to:

jtp.putClientProperty(LafWidget.TABBED_PANE_PREVIEW_PAINTER,
    new DefaultTabPreviewPainter());


where org.jvnet.lafwidget.tabbed.DefaultTabPreviewPainter is the default (reference) implementation:

public class DefaultTabPreviewPainter extends TabPreviewPainter {
  public boolean hasPreview(JTabbedPane tabPane, int tabIndex) {
    return (tabPane.getComponentAt(tabIndex!= null);
  }

  public void previewTab(JTabbedPane tabPane, int tabIndex, Graphics g,
      int x, int y, int w, int h) {
    Component tabComponent = tabPane.getComponentAt(tabIndex);
    if (tabComponent == null)
      return;
    // if (!tabComponent.isShowing())
    // return;
    int compWidth = tabComponent.getWidth();
    int compHeight = tabComponent.getHeight();

    if ((compWidth > 0&& (compHeight > 0)) {
      // draw tab component
      BufferedImage tempCanvas = new BufferedImage(compWidth, compHeight,
          BufferedImage.TYPE_INT_ARGB);
      Graphics tempCanvasGraphics = tempCanvas.getGraphics();
      tabComponent.paint(tempCanvasGraphics);

      // check if need to scale down
      double coef = Math.min((doublew / (doublecompWidth, (doubleh
          (doublecompHeight);
      if (coef < 1.0) {
        int sdWidth = (int) (coef * compWidth);
        int sdHeight = (int) (coef * compHeight);
        int dx = (w - sdWidth2;
        int dy = (h - sdHeight2;

        g.drawImage(LafWidgetUtilities.createThumbnail(tempCanvas,
            sdWidth), dx, dy, null);

      else {
        // System.out.println("Putting " + frame.hashCode() + "
        // -> " + snapshot.hashCode());
        g.drawImage(tempCanvas, 00null);
      }
    }
  }

  public boolean hasPreviewWindow(JTabbedPane tabPane, int tabIndex) {
    return true;
  }

  public boolean hasOverviewDialog(JTabbedPane tabPane) {
    return true;
  }
}


Sample implementation that specifies tab overview that is updated periodically (every 3 seconds):

jtp.putClientProperty(LafWidget.TABBED_PANE_PREVIEW_PAINTER,
  new DefaultTabPreviewPainter() {
    @Override
    public boolean toUpdatePeriodically(JTabbedPane tabPane) {
      return true;
    }

    @Override
    public int getUpdateCycle(JTabbedPane tabPane) {
      return 3000;
    }
  });

LafWidget. TEXT_SELECT_ON_FOCUS
since version 1.0

Specifies that a text component should select all its contents on focus gain. The value should be either Boolean.TRUE (behaviour present) or Boolean.FALSE and can be set either on a specific text component or globally on UIManager. Example of creating a text field that selects all its contents on focus gain:

    JTextField jtf4 = new JTextField("select all on focus");
    jtf4.setColumns(20);
    jtf4.putClientProperty(LafWidget.TEXT_SELECT_ON_FOCUS, Boolean.TRUE);


The result is:


LafWidget. TEXT_EDIT_CONTEXT_MENU
since version 1.0

Specifies that a text component should have edit context menu. The value should be either Boolean.TRUE (behaviour present) or Boolean.FALSE and can be set either on a specific text component or globally on UIManager. Example of creating a text field with edit context menu:

    JTextField jtf5 = new JTextField("edit context menu");
    jtf5.setColumns(20);
    jtf5.putClientProperty(LafWidget.TEXT_EDIT_CONTEXT_MENU, Boolean.TRUE);


The result is:


LafWidget. TREE_AUTO_DND_SUPPORT
since version 1.0

Specifies that a tree should provide automatic drag-n-drop (DnD) support. The value should be either Boolean.TRUE (behaviour present) or Boolean.FALSE and can be set either on a specific tree or globally on UIManager. Example of creating a tree with automatic DnD support:

    tree.putClientProperty(LafWidget.TREE_AUTO_DND_SUPPORT,
        Boolean.TRUE);


The result is - the first screenshot shows the drop enabled (gson21 is being dragged), while the second screenshot shows the drop disabled (gson11 is being dragged under one of its children):