![]() ![]() |
Below is the code from SimpleSingleCustomizerSample.java that creates and configures the JCustomizer and the JCustomizerPane.
Try this:
using Java Web Start.
- Select the JCustomizer by clicking it. Then the handles appear. You can move and resize the component with the mouse. When you release the JCustomizer it snaps to the grid. If you resize the frame the grid adjusts to its size.
- // create a pane that supports customizers and "snap-to-grid" feature
- JCustomizerPane pane = new JCustomizerPane();
- // create a CustomizerLayout
- InfiniteTableLayout itl = new InfiniteTableLayout(50, 50, pane);
- // set the layout
- pane.setCustomizerLayout(itl);
- // create a JCustomizer that wraps a component and listens to mouse events
- JCustomizer simpleCustomizer = new JCustomizer(new JLabel("A Simple Component"));
- // add it to the JCustomizerPane
- pane.addCustomizer(simpleCustomizer, new AbsoluteTableConstraints(50, 50, 150, 50, simpleCustomizer, itl));
AbstractTextCustomizer
is a base class to write customizers for components, which can display
texts, with inline-editing support. The framework provides 3 implementations:
Below is the code from TextCustomizersSample.java that creates and configures the text customizers.
Try this:
using Java Web Start.
- Double-click a text editor to edit its text and resize the JHtmlCustomizer to see how the text wraps automatically!
- // create a CustomizerLayout
- InfiniteTableLayout itl = new InfiniteTableLayout(customizerPane);
- // set the layout
- customizerPane.setCustomizerLayout(itl);
- // create a JLabelCustomizer, which supports inline editing of a text
- JLabelCustomizer labelCustomizer = new JLabelCustomizer("A Label Customizer - double click to edit!");
- // add it to the JCustomizerPane
- customizerPane.addCustomizer(labelCustomizer, new AbsoluteTableConstraints(50, 50, 270, 20, labelCustomizer, itl));
- // create a JButtonCustomizer to customize a button using the String constructor.
- JButtonCustomizer buttonCustomizer = new JButtonCustomizer("Double click to edit this button!");
- // add it to the JCustomizerPane
- customizerPane.addCustomizer(buttonCustomizer, new AbsoluteTableConstraints(300, 100, 210, 50, buttonCustomizer, itl));
- // create a JButtonCustomizer to customize a JCheckBox
- JButtonCustomizer checkBoxCustomizer = new JButtonCustomizer(new JCheckBox("Double click to edit this check box!", true));
- // set the background color to white
- checkBoxCustomizer.setBackground(Color.WHITE);
- // add it to the JCustomizerPane
- customizerPane.addCustomizer(checkBoxCustomizer, new AbsoluteTableConstraints(30, 160, 250, 20, checkBoxCustomizer, itl));
- // create a JButtonCustomizer to customize a JRadioButton
- JButtonCustomizer radioButtonCustomizer = new JButtonCustomizer(new JRadioButton("Double click to edit this radio button!", true));
- // set the background color to white
- radioButtonCustomizer.setBackground(Color.WHITE);
- // add it to the JCustomizerPane
- customizerPane.addCustomizer(radioButtonCustomizer, new AbsoluteTableConstraints(300, 200, 270, 20, radioButtonCustomizer, itl));
- // create a JHtmlCustomizer, which supports inline editing of a text
- JHtmlCustomizer htmlCustomizer = new JHtmlCustomizer();
- // set some HTML text
- htmlCustomizer.setHtmlBody("<b>This is an <i>editable</i> HTML</b> text! Double click!<br> " +
- "<a href=\"http://www.softsmithy.org\">This is a link!</a><br>" +
- "<font color=\"#FF0000\">And this </font>" +
- "<font color=\"#00FF00\">is a </font>" +
- "<font color=\"#00FFFF\">colored text!</font><br><br>" +
- "This is a very long text that shows automatic line wrapping!");
- // add it to the JCustomizerPane
- customizerPane.addCustomizer(htmlCustomizer, new AbsoluteTableConstraints(150, 250, 270, 150, htmlCustomizer, itl));
Implementing your own text customizer can be quite easy. Have a look at the source code of JLabelCustomizer for an example. (The source code gets shipped with the library or can be retrieved from the Subversion repository of the SoftSmithy project).
![]() ![]() |