jtableheader

Set Column Width of JTable by Percentage

自作多情 提交于 2019-12-18 13:36:02
问题 I need to assign a fixed width to a few columns of a JTable and then an equal width to all the other columns. Suppose a JTable has 5 columns. The first column should have a width of 100 and the second one a width of 150. If the remaining width of the JTable is 600 after setting the width of the two columns, I'd like to evenly split it among the other three columns. The problem is table.getParent().getSize().width is often 0, even if it is added to the JFrame and visible, so I can't use it as

Java JTable Column headers not showing

拈花ヽ惹草 提交于 2019-12-18 08:58:28
问题 Hi guys was hoping you could help me out here, my code (Logic-wise) is all good the only problem is that the column headers do not show up in the 2 tables (table and tableS, one for teacher and one for student details) how do i make them show? import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; public class Display { ArrayList<Student> stud1 = new ArrayList<Student>(); ArrayList<SubjectTeacher> sTeach1 = new ArrayList<SubjectTeacher>(); /

Wrong column being sorted when JTable Header clicked

◇◆丶佛笑我妖孽 提交于 2019-12-18 07:16:18
问题 I have the following code for a RowSorterListener . The purpose of this is to sort a column without affecting any other columns. import javax.swing.event.RowSorterListener; import javax.swing.event.RowSorterEvent; import javax.swing.JTable; import javax.swing.RowSorter.SortKey; import java.util.List; import java.util.Arrays; public class UnrelateData implements RowSorterListener { JTable table; int columnSorted = -1; Object[][] dataStore; public UnrelateData(JTable table) { this.table = table

How to make the defaulttablemodel table header bold

不羁岁月 提交于 2019-12-13 10:24:43
问题 I want to make the header of a jtable with defaulttablemodel BOLD. Here's my code class TablePanel extends JPanel { private String[] COLUMNS = {"FAMILY MEMBERS", "STAR (NAKSHATRA)"}; private DefaultTableModel model = new DefaultTableModel(COLUMNS, 0){ public boolean isCellEditable(int row, int column) { return false; } }; DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(){ public void setHorizontalAlignment(int alignment) { alignment = (int) CENTER_ALIGNMENT; }; };

JTable Swing: I cannot resize column by dragging cursor in header

心不动则不痛 提交于 2019-12-13 07:09:05
问题 I cannot resize the column width by moving the cursor between header columns and drag the divider, despite of that I have set setResizingAllowed() to true . tbResumen = new JTable(); tbResumen.setEnabled(false); tbResumen.setRowHeight(20); tbResumen.setBackground(UIManager.getColor("Table.selectionBackground")); tbResumen.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null)); tbResumen.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); tbResumen.setFont(new Font(

Java JTable cannot set width of column

前提是你 提交于 2019-12-12 18:29:28
问题 I try to set width for the columns, but it didn't work at all, I have been searching for answers for hours, and here is my code, can anyone tell me what is the problem. Thanks in advance. String [] columns = {"Day","StratTime","EndTime","Description"}; mtbl = new DefaultTableModel(); tbl = new JTable(mtbl); jsPane = new JScrollPane(tbl); tbl.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); for (int i = 0; i < Timedcolumns.length; i++) { mtbl.addColumn(columns[i]); tbl.getColumnModel().getColumn(i)

Add ActionListener to Column Header of JTable

时光毁灭记忆、已成空白 提交于 2019-12-12 11:01:35
问题 Is it possible to add an ActionListener to a column header for JTable . Here is my table Now, I want to add an ActionListener to the column headers (e.g. WQE , SDM ) I would like to be able to show the column description in another window. 回答1: See fully working example below add a MouseListener to the column header use table.columnAtPoint() to find out which column header was clicked Code: // example table with 2 cols JFrame frame = new JFrame(); final JTable table = new JTable(new

Setting column headers in JTable

此生再无相见时 提交于 2019-12-12 10:35:36
问题 I have the following JTable which uses a table model: http://s17.postimage.org/7zfh3l4lr/Screen_Shot_2012_03_10_at_15_11_31.png Instead of using, A,B,C,D etc. how can I define my own table names. This is my code Here is the code for my table model, the frame creates an object from this table model and displays it in a JFrame. package uk.ac.kcl.inf._4css1pra.spreadsheet; import java.awt.Dimension; import java.util.HashMap; import java.util.Map; import javax.swing.table.AbstractTableModel; /**

Java - ResultSet change Db column names to show in JTable

拈花ヽ惹草 提交于 2019-12-11 14:49:52
问题 I am using rs2xml .jar for populating data into table. here is my code of showing table columns and data ResultSet rs = stmt.executeQuery("select * from employees"); table_employees.setModel(DBUtiles.resultSetToTableModel(rs)); This code successfully works But I want to rename the columns. I don't want to show the DB Columns in my table. 回答1: You need to update the TableColumn from the TableColumnModel : TableColumnModel tcm = table.getColumnModel(); tcm.getColumn(0).setHeaderValue("whatever

JTable Missing Column Headers

不羁的心 提交于 2019-12-11 10:29:35
问题 Really simple question. Don't bash me please. :) I created a table model by extending AbstractTableModel as follows: public class InventoryTableModel extends AbstractTableModel { private static final String[] COLUMN_NAMES = { "On Sale", "Name", "Selling Price", "Description" }; @Override public int getColumnCount() { return COLUMN_NAMES.length; } @Override public int getRowCount() { return 0; } @Override public String getColumnName(int columnIndex) { return COLUMN_NAMES[columnIndex]; }