What is the use of JTable class?
Hi all,
I am learning advanced java programming. This programming sounds very difficult to understand than C++ programming. I need you help to know about the 'class JTable'. This class is something related to creating table java, and this is the only which I know about JTable class. If you have knowledge about the JTable class of java, then please let me know the same. I would greatly appreciate your any help.
Re: What is the use of JTable class?
The JTable is used to display and edit regular two-dimensional tables of cells. The JTable has many facilities that make it possible to customize its rendering and editing but provides defaults for these features so that simple tables can be set up easily. Note that if you wish to use a JTable in a standalone view (outside of a JScrollPane) and want the header displayed, you can get it using getTableHeader() and display it separately.
Re: What is the use of JTable class?
Hi friend,
I have one example of java which will demonstrate you the use of JTable class:
Code:
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class JTableDemo {
public static void main(String args[]) {
JFrame frp = new JFrame();
frp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" },
{ "Row2-Column1", "Row2-Column2", "Row2-Column3" } };
Object columnNames[] = { "Column One", "Column Two", "Column Three" };
JTable table = new JTable(rowData, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
frp.add(scrollPane, BorderLayout.CENTER);
frp.setSize(200, 150);
frp.setVisible(true);
}
Re: What is the use of JTable class?
The JTable class of java is basically used for to create tables. Following are some constructors of the JTable class: - JTable(Vector rData, Vector Namesofcolumn)
- JTable(TableModel tdm, TableColumnModel tcm, ListSelectionModel sm)
- JTable(TableModel tdm, TableColumnModel tcm)
- JTable(TableModel tdm)
- JTable(int Rowsnum, int Columnsnum)
Re: What is the use of JTable class?
I have coded one java example using JTable class. When you run below code, it will create table with 12 rows and 6 columns:
Code:
import javax.swing.JTable;
import javax.swing.JScrollPane;
public class TJDemo
{
public static void main(String[] argt)
{
JTable tnl = new JTable(12, 6);// it will create a table with 12 rows and 6 columns
JScrollPane scrollPane = new JScrollPane(tnl);
}
}
Re: What is the use of JTable class?
Hi,
Below are some methods of JTable class of java, please go through them:
- createScrollPaneForTable(JTable tle)
- ditCellAt(int rw, int clm, EventObject eo)
- editingStopped(ChangeEvent ev)
- columnSelectionChanged(ListSelectionEvent ev)
- columnAtPoint(Point pt)
- addRowSelectionInterval(int 0index, int 1index)