Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Setting the Margin Between Cells in a JTable

                         

In this section, you will learn how to set the margin (Gap) between cells in a JTable component. Here we are providing you an example with code that arranges the column margin (Horizontal space) and row margin (Vertical space). Whenever you increase the column margin, you will get the cell widths  increased automatically. Unlike column margin, row margin does not increase automatically, whenever row margin has been increased. 

Description of program:

This program helps you for how to set the margin in JTable. For this first of all, you will create a JTable containing the data and columns with column header. The column header have the column name. Then you will have to set the internal gaps (space) between the cells through the setIntercellSpacing() method. Now apply the SetRowHeight() method for setting the height of rows through using the setRowHeight() method. The entire process has completed now, you will get the set margin between cells in a JTable.

Description of code:

setIntercellSpacing(Dimension dim):
This is the method sets the row margin and column margin. It takes 'Dimension' type data.

        dim: It specifies the new height and width between cells.

getRowHeight():
This method returns the height of a row in pixels.

setRowHeight(int row, int row_height):
This is the method to set the height of a row. It takes two integer types arguments:

        row: This is the row that have to be changed.
        row_height: It defines the  height of  a row in pixels.

Here is the code of program:

import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;

public class CellGap{
  JTable table;
  public static void main(String[] args) {
    new CellGap();
  }

  public CellGap(){
    JFrame frame = new JFrame("Setting the margin in JTable Component!");
    JPanel panel = new JPanel();
    String data[][] {{"Vinod","Computer","3"},
                       {
"Rahul","History","2"},
                       {
"Manoj","Biology","4"},
                       {
"Sanjay","PSD","5"}};
    String col [] {"Name","Course","Year"};
    DefaultTableModel model = new DefaultTableModel(data,col);
    table = new JTable(model);
    Dimension dim = new Dimension(20,1);
    table.setIntercellSpacing(new Dimension(dim));
    SetRowHight(table);
    table.setColumnSelectionAllowed(true);
    JTableHeader header = table.getTableHeader();
    header.setBackground(Color.yellow);
    JScrollPane pane = new JScrollPane(table);
    panel.add(pane);
    frame.add(panel);
    frame.setSize(500,150);
    frame.setUndecorated(true);
    frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
  }
  public void SetRowHight(JTable table){
    int height = table.getRowHeight();
    table.setRowHeight(height+10);
  }
}

Download this example.

Output of program:

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

hello sir

I want to print my Jtable Records in Netbeans
what I use to do that ..????????

Posted by Anju on Monday, 09.15.08 @ 17:02pm | #79587

Latest Searches:
jdk1.4
sample palindrome prog
type casting
VNCj (Java VNC S
Java com
datalist
jsp bean get property
/n java
menu gui
java inner class
java counter
t:datalist
how to save JDBC Conne
B Tree implementation
how to installmcat
Logger
java random numbers
panelGrid/
Javascript Menus Image
spring
clear grid dojo
fjhjf
JSP forward
struts custom tag
MULTIPLE SELECT COMBO
is the jvm same for al
insert data to text fi
panelgrid colspan
game in java
String to array in jav
iBatis Stored Procedur
rules
Photoshop
Linux Caixa MаÐ??аÐ?
J2ME Recordstore
Java code for media pl
add row, delete row an
JPA Tutorials
Take user input using
java programmes
debugging java
JSP:File Input Paramet
is the jvm same for al
how to write hql in da
jms examples
ArrayList
Inserting data from gu
creating eclipse insta
Struts
random walk generator
basic about struts
disable Jframe
jQuery to Select Multi
strtuts2
deployment of ejb in w
Mercurial
DTO
Lookup Dispatch Action
customise css in jsp
Photoshop Effects Grun
jsp type 4 connection
ะ ย ะà¸???ะÂ
Eclipse 3.4 EJB
jsp applet netbeans
insert calendar image
mysql query
cache control
set tooltip row jtable
Photoshop Effects Hole
how will we set enviro
get column count colu
saving a file in a fol
xml
datatree
SCJP 6
EJB example program
400 book
java program examples
diplay North American
how to call css file f
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.