BEA 8.1 Certified Administrator, IBM Certified Solution Developer For XML 1.1 and Related Technologies, SCJP, SCWCD, SCBCD, SCDJWS, SCJD, SCEA,
Oracle Certified Master Java EE 5 Enterprise Architect
Originally posted by SrinivasMA Srini:
Hi,
If you design your table model like this, your problem hopefully be solved.
public class DataTableModel extends AbstractTableModel { }
Make a trail.
Cheers
Srinivas
SCJP,SCJD
Column Widths
It is very easy to change the column widths on a JTable. First, you must create a new TableColumn object and set it to null. Next, you must specify which column whose size you would like to change. Last, you must use the method setPreferredWidth(int) method to change the size. If you would like to change all the column sizes, you might want to run a simple for loop to do this task.
Add the following code after: table.setShowVerticalLines(false);
TableColumn column = null;
column = table.getColumnModel().getColumn(1);
column.setPreferredWidth(200);
This code will change the width of the second column. Compile and run the application to see this change take place.
BEA 8.1 Certified Administrator, IBM Certified Solution Developer For XML 1.1 and Related Technologies, SCJP, SCWCD, SCBCD, SCDJWS, SCJD, SCEA,
Oracle Certified Master Java EE 5 Enterprise Architect
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
BEA 8.1 Certified Administrator, IBM Certified Solution Developer For XML 1.1 and Related Technologies, SCJP, SCWCD, SCBCD, SCDJWS, SCJD, SCEA,
Oracle Certified Master Java EE 5 Enterprise Architect
Originally posted by Billy Tsai:
because I just dont feel good looking at the coloumns being moved and also I cant allow the coloumns being changed to a different position because I use use mouseListen to get the name of the currently clicked selected coloumn, and if the name coloumn is being moved to another position instead of being the first coloumn then the information I get could be the location , size etc... but I want the name
if there is a away to disable dragging the coloumns please tell me thanks
By default, columns may be rearranged in the JTable so that the view's columns appear in a different order to the columns in the model. This does not affect the implementation of the model at all: when the columns are reordered, the JTable maintains the new order of the columns internally and converts its column indices before querying the model.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
BEA 8.1 Certified Administrator, IBM Certified Solution Developer For XML 1.1 and Related Technologies, SCJP, SCWCD, SCBCD, SCDJWS, SCJD, SCEA,
Oracle Certified Master Java EE 5 Enterprise Architect
In JTable, we can drag columns. .... If I want to avoid this, are there any ways to do?
Thanks, I got it.
I have a problem while displaying data in JTable. I want to display rate column right justified. Rate contains rate and currency symbol. Is there any way to set the alignment for any particular column, or is there any work around?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Hopefully you also got that I think this is a really bad idea. To recap why:
users are used to being able to rearrange columns to suit their way of looking at data
the JTable already hides the movement of columns from you, so your coding should be the same whether you allow the columns to be dragged or not.
If you make your own TableModel you can easily override the getColumnClass() method and have it return an Integer for the given column. It doesnt matter that the data in that column is not a pure Integer - it is just used to determine how to layout the data.
BEA 8.1 Certified Administrator, IBM Certified Solution Developer For XML 1.1 and Related Technologies, SCJP, SCWCD, SCBCD, SCDJWS, SCJD, SCEA,
Oracle Certified Master Java EE 5 Enterprise Architect
I did the same. But if developer wish to set size for columns, TableColumn.getHeaderRenderer() will return null. This was problem in 1.3.x, and still there is problem in 1.4.x it seems. I tried on 1.4.1, and still it returns null. I left the default implementation(all columns have equal widths).
Comments are welcome.
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|