Column Header in JTable


,
can we set the font of column header of a JTable .
please reply soon ..
Posted On: Tuesday 23rd of October 2012 10:55:19 PM Total Views:  63
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




JTable column non-focusable?

How would you set a column in a JTable to make it unable to gain focus i.e. select the next column on the same row or ignore the command completely when selecting a column that should not be able to be gained focus on
VIEWS ON THIS POST

44

Posted on:

Wednesday 17th October 2012
View Replies!

Changing the column name in JTable

I am creating a table using swings JTable with some columns. i need to change the column names when i click on a particular button. How can i achieve my target
VIEWS ON THIS POST

33

Posted on:

Thursday 18th October 2012
View Replies!

TableSorter (Can you skip a column?)

, I'm working with JTables (It's good stuff.) and am using TableSorter to add cool, column-sorting goodness to my application. It works. It's fantastic. I get giddy just thinking about it. My problem lies in the fact that I'd like to have a nifty little column on the left which holds the row number (like any spiffy database/spreadsheet thingie should). I'd like these to remain starting at 1 and incrementing per record...you know the deal. So, what I have to do is figure out how to get TableSorter to skip that particular column. When I look at the TableSorter code, I'm "Like, woah." Can anyone point me in the right direction
VIEWS ON THIS POST

44

Posted on:

Thursday 18th October 2012
View Replies!

JTable column header

hi, this should be an easy question but I'm stuck is there any method to change the Column names of a JTable after creating it(Sure there is) to get the name of the Column,we can use the method of AbstractTableModel getColumnName(int col). is that right any help is appreciated
VIEWS ON THIS POST

41

Posted on:

Thursday 18th October 2012
View Replies!

JTable column widths

I'm having trouble setting the widths of the columns of my table. There's only 2 of them and they're coming out so wide they're crowding out stuff on the other sides. What I've tried thus far: 1) set the widths in my own tableColumn model from an object[] that has the widths. TableColumn column = new TableColumn(i, paceTblData.columnData[i].width, renderer, null);
VIEWS ON THIS POST

41

Posted on:

Thursday 18th October 2012
View Replies!

jtable, table model, column headers

Dear all, I am using jbuilder 10 for an application and I have bumped on a glitch. I create my own tablemodel (which inherits from the AbstractTableModel) do the necessary work (implementing the abstract methods) and I also override getColumnName method. However, when the application starts no column headers appear (even though when I pass my tabled model in teh JTable constructor getColumnName is called). At first I believed that I had made a mistake with my table model class but when I used the FileTableModel class from O'Rilley's JFC book same thing happened. Does anyone have any idea why this is happening thanks in advance dimitris ps this is my table model -------------------------------------------------------------------------- package testapp; import javax.swing.table.*; import java.util.Vector; public class DataModel extends AbstractTableModel { protected String[] columnNames; protected Vector data; protected Class[] columnClasses = new Class[] {String.class, Boolean.class}; public DataModel(Vector data, String[] columnNames) { this.data = data; this.columnNames = columnNames; fireTableStructureChanged(); } public int getRowCount() { return data.size(); } public int getColumnCount() { return columnNames.length; } public Object getValueAt(int rowIndex, int columnIndex) { switch (columnIndex) { case 0: return data.elementAt(rowIndex); case 1: return (Object) new Boolean(true); default: return null; } } public void removeValueAt(int rowIndex, int columnIndex) { data.removeElementAt(rowIndex); fireTableRowsDeleted(rowIndex, columnIndex); } public void insertElementAt(Object o, int index){ this.data.insertElementAt(o, index); fireTableRowsInserted(index, index); } public void append(Object o) { this.data.add(o); fireTableRowsInserted(data.size()-1, data.size()-1); } public String getColumnName(int columnIndex) { return columnNames[columnIndex]; } public Class getColumnClass(int col) { return columnClasses[col]; } } ---------------------------------------- and this is how i call it from the mainFrame Vector data = new Vector(); String[] columnNames = new String[] {"column 1", "column 2"}; DataModel dm = new DataModel(data, columnNames) JTable table = new JTable(dm) , yeap that was it. I needed either a scrollpane or explicitly get the headers there. Thanx for the help. good day
VIEWS ON THIS POST

158

Posted on:

Thursday 18th October 2012
View Replies!

Make table column invisible

Hi , The following code make the column invisible, but also removes it from the model. table.getColumnModel().removeColumn(table.getColumnModel().getColumn(0)); How can I make the column invisible, but *not* remove it from the model, because I need to obtain the data from the invisible column later on. Also, this is not working, since when I increase column width by dragging I can see some dots and the coumn becomes partially visible: TableColumn idClmn= table.getColumn("Property id"); idClmn.setMaxWidth(0); idClmn.setMinWidth(0); idClmn.setPreferredWidth(0);
VIEWS ON THIS POST

80

Posted on:

Thursday 18th October 2012
View Replies!

JTable set column data type

Hi folks. Is it possible to set a column in JTable to a certain data type I mean to set a column to integer data type for example and when is user trying to input non-integer value it will do nothing. Or do I have to solve this in other way like adding a listener and conditions to all cells in the column Martin
VIEWS ON THIS POST

58

Posted on:

Sunday 21st October 2012
View Replies!

How to wrap column name in swing

Hi Folks, I am fetching some data from database and showing it in jtable by using AbstractTableModel. Now the columns which I am fetching has some long description like 'Payment Method' is showing 'Payment Met...'. How can I wrap those column name . Please suggest me some solution. regards......
VIEWS ON THIS POST

55

Posted on:

Sunday 21st October 2012
View Replies!

Checkbox editor for JTable column

I have written checkbox editor for JTable column. I am bale to see checkbox and can select or deselect it. But if I select row 1 checkbox and then if click on row 2 checkbox, the selected checkbox of row 1 disappers, it becomes false again. That is I can select only one checkbox. I am not getting what i written wrong in editor. Please someone can help me. import java.awt.Color; import java.awt.Component; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.EventObject; import javax.swing.DefaultCellEditor; import javax.swing.JCheckBox; import javax.swing.JTable; import javax.swing.SwingConstants; import javax.swing.event.CellEditorListener; /* * can extends AbstractCellEditor */ public class GenTableCellEditor extends DefaultCellEditor implements ItemListener { protected static JCheckBox checkBox = new JCheckBox(); public GenTableCellEditor() { super(checkBox); checkBox.setHorizontalAlignment(SwingConstants.CENTER); checkBox.setBackground(Color.white); } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { if (value == null) return checkBox; checkBox.addItemListener(this); if (((Boolean) value).booleanValue()) checkBox.setSelected(true); else checkBox.setSelected(false); return checkBox; } public Object getCellEditorValue() { if(checkBox.isSelected() == true) return new Boolean(true); else return new Boolean(false); } @Override public void addCellEditorListener(CellEditorListener l) { // TODO Auto-generated method stub } @Override public void cancelCellEditing() { // TODO Auto-generated method stub } @Override public boolean isCellEditable(EventObject anEvent) { // TODO Auto-generated method stub return true; } @Override public void removeCellEditorListener(CellEditorListener l) { // TODO Auto-generated method stub } @Override public boolean shouldSelectCell(EventObject anEvent) { // TODO Auto-generated method stub return true; } @Override public boolean stopCellEditing() { // TODO Auto-generated method stub return true; } @Override public void itemStateChanged(ItemEvent e) { // TODO Auto-generated method stub System.out.println("Firing!"); } }
VIEWS ON THIS POST

67

Posted on:

Sunday 21st October 2012
View Replies!

how to get column position and row position from jtextarea

i want logic like notepad in which status bar updating with row position and column position. any idea.....:-)
VIEWS ON THIS POST

53

Posted on:

Monday 22nd October 2012
View Replies!

JTable columns widths reset after model change

Howdy Ranchers! The original question was posted in the SCJD forum here, but I will shortly explain what the problem is. I've noticed that if I set the column widths using: columnModel.getColumn(i).setPreferredWidth(...)
VIEWS ON THIS POST

59

Posted on:

Monday 22nd October 2012
View Replies!

auto adjust column widths

Can anyone point me to some code that will set jtable column widths based on column titles and data in cells. There was some code in the Java tutorials but it didn't behave as I thought it would. It only took the column titles into account. They do something with cells but no data is used. I included the code below: /* * This method picks good column sizes. * If all column heads are wider than the column's cells' * contents, then you can just use column.sizeWidthToFit(). */ private void initColumnSizes(JTable table) { MyTableModel model = (MyTableModel)table.getModel(); TableColumn column = null; Component comp = null; int headerWidth = 0; int cellWidth = 0; Object[] longValues = model.longValues; TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); for (int i = 0; i < 5; i++) { column = table.getColumnModel().getColumn(i); comp = headerRenderer.getTableCellRendererComponent( null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; comp = table.getDefaultRenderer(model.getColumnClass(i)). getTableCellRendererComponent( table, longValues[i], false, false, 0, i); cellWidth = comp.getPreferredSize().width; if (DEBUG) { System.out.println("Initializing width of column " + i + ". " + "headerWidth = " + headerWidth + "; cellWidth = " + cellWidth); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
VIEWS ON THIS POST

43

Posted on:

Monday 22nd October 2012
View Replies!

Is it possible to Drag and Drop among columns in a Same JTable

Can I use drag and drop operation among the columns of a JTable
VIEWS ON THIS POST

38

Posted on:

Monday 22nd October 2012
View Replies!

JTable - single column header won't change from "A"

I've tried numerous ways of changing the column header for the single column in a JTable. The following code WORKS in a simple example app I made, but doesn't work in my "real app". Is there something that could be "blocking" changing the column header assignment I use a "new" DefaultEditor" or "Default renderer" but I don't mess with any headers in them JTableButtonModel defaultTableModel = new JTableButtonModel(); jTRXAssignedSlices = new JTable(defaultTableModel); int viewColumn = jTRXAssignedSlices.convertColumnIndexToView(0); TableColumn column = jTRXAssignedSlices.getColumnModel().getColumn(viewColumn); column.setHeaderValue("Receive Slices"); jTRXAssignedSlices.getTableHeader().repaint(); jTRXAssignedSlices.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); jTRXAssignedSlices.setShowHorizontalLines(false); jTRXAssignedSlices.setShowVerticalLines(false); jTRXAssignedSlices.setDefaultEditor(JPanel.class, new JComponentCellEditor()); jTRXAssignedSlices.setDefaultRenderer(JPanel.class, new JListSliceCellRenderer()); jTRXAssignedSlices.setPreferredScrollableViewportSize(new Dimension(120, 200));
VIEWS ON THIS POST

32

Posted on:

Monday 22nd October 2012
View Replies!

how to avoid column's position change in jTable

hi , write an application in which i display a JTable containig result from database. Everything works fine but i discover that JTable gives the user a chance to change columns' positions when the JTable is displayed. i want to prevent the user from doing this change in JTable's columns positions. How can i perform that. Many
VIEWS ON THIS POST

44

Posted on:

Monday 22nd October 2012
View Replies!

Binding a JTable column to a bound combobox

NetBeans makes it easy to create a Jtable and bind it to a table from an SQL database, thanks to TopLink Essentials. ...But how do I bind a column in the database to a particular table Let's say you have a table called Employees. Each row contains a unique ID#, a name (e.g. John Smith) and the ID of the employee's department. You may edit the table to change any of this information. This table has been bound to a Jtable called EmployeesTable. I would like to edit each employee's department not as a number but as a combobox populated with the department names (Sales, Marketing, etc.), pulled from another table (called Departments, let's say). When the user selects the department name, the ID# of the department should be fed back to the column in that row of the table. Binding an SQL table to a JComboBox is trivial, thanks to the BeansBinding tools. However, I haven't figured out how to bind *all* entries in a column of a JTable that way. I've been trying to figure this out since October, without success. *Any* advice would be appreciated. Although I'm not new to programming, I am new to Java. Thank you for your time.
VIEWS ON THIS POST

52

Posted on:

Monday 22nd October 2012
View Replies!

Resizing columns in Tree table

Hi ! Iam using Tree Table in my application. Which is already written by somebody else. But when i try to resize the column width it is not increasing. Iam not getting where the thing is went wrong. I checked almost in all the area, but I didn't fixed it. Can any body having idea about this. Please help me if so,
VIEWS ON THIS POST

33

Posted on:

Monday 22nd October 2012
View Replies!

JTable - editable columns

everybody, Can somebody tell me, how to use this code to allow or to disable editing different columns, if it is possible (this code is taken from http://www.javaalmanac.com/egs/javax.swing.table/NoEdit.html ) JTable table1 = new JTable() { public boolean isCellEditable(int rowIndex, int vColIndex) { return false; } }; OK, I already found the answer, I think. confModel = new DefaultTableModel(new Vector(), new Vector()); JTable confTable = new JTable(confModel){ public boolean isCellEditable(int rowIndex, int colIndex) { if (colIndex < 2) { return false; } else { return true; } } }; [ May 12, 2006: Message edited by: Bodhi Karam ]
VIEWS ON THIS POST

28

Posted on:

Monday 22nd October 2012
View Replies!

Dynamically redrawing columns in TableViewer

Does anyone know how to reset column names, properties, etc dynamically. For instance, my application allows the user to add rows as well as columns. When a new row is added to the input, it appears in the table viewer upon refresh(). But what do I have to do to force a new column to appear when the user chooses to add one. Currently, I'm doing these steps: 1. Making a call to TableViewer::setColumnProperties() with the new column names. 2. Reformatting TableViewer::getTable() to include new columns. 3. Resetting TableViewer::setCellEditors() to create the correct number of editors as a result of adding a column. But having no joy with this:-(. If I step through the code, it has the new column name both in table viewer's properties as well in the column names of TableViewer::getTable(), but it just wouldn't redraw the table. Have spent too much time on this.
VIEWS ON THIS POST

74

Posted on:

Tuesday 23rd October 2012
View Replies!