Saturday, May 12, 2012

How to customize jTable using Netbeans

Learn how to customize jtable using Netbeans. In this post we learn how to set color grid line,Visibility of vertical and horizontal grid line, and how to set foreground color to selected cell. A simple single line code tell us how to customize jtable.
  • First create global object for DefaultTableModel and create settable() method in constructor.
  • See my previous post How to set color in jTable column header using NetBeans for how to call settable() method.
  • Code for settable() method :
 private void settable() {
        String values[][] = {{"Arun", ""}, {"Digvijay", ""}, {"Raj", ""}};
        String title[] = new String[]{"Blogger Name", "Blogger website"};
        dm = new DefaultTableModel(values, title);
  • Out put :
  • Setting grid line color add single line code given below in the settable() method. As we know jtable has default color which is black.
  • Out Put :

  • Display jTable without grid layout by adding single line code in settable() method.
  • Out Put :
  • Showing only horizontal and vertical grid lines.Change the code alternatively below you get out puts likes this.
  • For Displaying only horizontal lines.
  • Out put :
  • Display only Vertical grid lines.
  • Setting foreground color to selected cell in jTable.

    Thanks for reading this post. Hope you find best.

2 Responses so far

  1. Unknown says:

    can the background color of the remaining grey area shown in the screenshoot be painted to a particular color?

  2. Unknown says:

    Thanks for that really nice

Leave a Reply