Column column = new Column("email"); column.setDecorator(new Decorator() { public String render(Object row, Context context) { Customer customer = (Customer) row; String email = customer.getEmail(); String fullName = customer.getFullName(); return "<a href='mailto:" + email + "'>" + fullName + "</a>"; } }); table.addColumn(column);@see Column @see Table
Decorators use a chained prepare/update model to modify the graphics in which a component is painted. The prepare() method of each decorator in a component's decorator sequence is called in reverse order before the component's paint() method is called. prepare() returns an instance of Graphics2D that is passed to prior decorators, and ultimately to the component itself. This allows decorators to modify the graphics context before it reaches the component. After the component has been painted, each decorator's update() method is then called in order to allow the decorator to further modify the resulting output.
Decorators are not restricted to painting within the component's bounds. However, they are clipped to the bounds of the component's parent. They are not clipped to their own bounds because, due to the chained painting model, it is not safe assume that a clip applied to a given decorator during the prepare phase will be valid for subsequent updates, or even for painting the component itself; though a component paints into a copy of the final prepared graphics, it must still be clipped to the intersection of its own bounds and the current clip (not the intersections of all preceding decorator prepare() calls).
Example:
@author Stefan Rybacki
@see DefaultDecoration
JPanel panel=new JPanel(new GridBagLayout()); Decorator d=new Decorator(new JButton("Hello World!"), new CrossOutDecoration()); panel.add(d);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|