aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes change location of jtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "change location of jtable" Watch "change location of jtable" New topic
Author

change location of jtable

rohit.j Jahagirdar
Greenhorn

Joined: Jul 14, 2012
Posts: 2
hi friends,
i have ctreated a jtable.
i want to change the loacation of jtable at (120,120)
how to change the location?
please help..
the code is as below.


import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author ROHIT
*/
public class test
{

public static void main(String args[])
{
final List<TableCellEditor> editors = new ArrayList<TableCellEditor>(3);
String[] items1 = { "Red", "Blue", "Green" };
JComboBox comboBox1 = new JComboBox( items1 );
DefaultCellEditor dce1 = new DefaultCellEditor( comboBox1 );
editors.add(dce1);
Object[][] data =
{
{"Color", "Red"},
{"Shape", "Square"},
{"Fruit", "Banana"},
{"Plain", "Text"}
};
String[] columnNames = {"Type","Value"};
DefaultTableModel model = new DefaultTableModel(data, columnNames);
JTable table = new JTable(model)
{
// Determine editor to be used by row
public TableCellEditor getCellEditor(int row, int column)
{
int modelColumn = convertColumnIndexToModel( column );

if (modelColumn == 1 && row < 3)
return editors.get(row);
// return (TableCellEditor)editors.get(row);
else
return super.getCellEditor(row, column);
}
};
JScrollPane scrollPane = new JScrollPane( table );
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.getColumnModel().getColumn(0).setPreferredWidth(127);
table.getColumnModel().getColumn(1).setPreferredWidth(120);
System.out.println(table.getCellEditor());



JFrame ts=new JFrame("Billing System");
ts.add( scrollPane );
ts.setVisible(true);
ts.setSize(500,500);

}
}

Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1945
    
  28
Please UseCodeTags.

What do you mean by change the location. Do you mean the location of the frame on the screen or the JTable inside the frame.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: change location of jtable
 
Similar Threads
jtable combo box value
Edit cell with another JTable
Jtable Cell and ENTER key
MultiComponent JTable
Swing JCombobox and JTable issue