Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Jazz Up Your JTables with Reusable Classes-5 : Page 5


advertisement
3-D Border Affects
You can simulate 3-D affects by manipulating the border of a cell. Create a FlashBorderRenderer, which—like the FlashColorRenderer—uses the FlashProvider interface to determine the flash state of a cell. Inside the getTableCellRendererComponent() method, set the Border of the cell to raised to give it a 3-D effect:

public class FlashBorderRenderer { protected static final Border raised = BorderFactory.createRaisedBevelBorder(); protected static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1); protected static final Border focusBorder =
UIManager.getBorder("Table.focusCellHighlightBorder"); ... public Component getTableCellRendererComponent(...) { // Get the component from the delegate Component c = delegate.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column); // Convert view column to model column int mcol = table.convertColumnIndexToModel(column); // invert the colours to flash JComponent jc = (JComponent) c; // If an abstract button e.g JCheckBox then set // border painted to true if (jc instanceof AbstractButton) { ((AbstractButton) jc).setBorderPainted(true); } if (provider.isFlashOn(row, mcol)) { jc.setBorder(raised); } else { if (hasFocus) jc.setBorder(focusBorder); else jc.setBorder(noFocusBorder); } return c; }

Remember to register the BorderFlashRenderer inside the registerRendererForClass() method to add those 3-D flashing effects to the existing behavior.



Reusable Classes for All JTable Display Effects
Using the techniques outlined in this article, you built a few common classes that you can re-use for all your JTable display effects. With the Decorator pattern, you can dynamically bind renderers together to create complex combinations of user interface behavior. Applying the Provider interface decouples the renderers from the application and makes them portable, which means no more hard coding! So have fun adding color, border, and font effects to your JTables.



Lara D'Abreo is an independent consultant responsible for many commercially released Java products in the telco, database, and integration spaces. She is currently working on software to monitor application servers. to e-mail Lara.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap