jtable

Cell Renderer for JTable - coloured rows

半腔热情 提交于 2019-12-31 03:48:08
问题 I've been looking around for a solution to this and I can't make head nor tail from various places of how to get my table to do coloured rows without asking my own question. From every place I've looked I gather I need to use a cell renderer but the problem is I don't know how to apply it to my own situation. So I have a simple JTable with 3 columns and I simply want each row to be highlighted in either green, yellow or red depending on the value of a separate variable (not displayed in the

How to change background color of an edited cell in JTable?

 ̄綄美尐妖づ 提交于 2019-12-31 03:26:24
问题 I searched everywhere but I still can't seem to find an answer to my question. I've read all about cell renderers and cell editors but still no idea... I have a JTable, and I want to make sure that the users clearly see which cell they are editing. by default, the edited cell in JTable gets a darker border, but i would like to make the background green. I can make it green when selected, but as soon as I start entering data, the green background disappears and I'm writing into a white cell.

How to add horizontal/vertical scrollbars to JScrollPane

回眸只為那壹抹淺笑 提交于 2019-12-31 02:49:11
问题 I want to add horizontal scrollbars to my JScrollPane, because my table right now looks like the one below: Here is my code to create the table: this.table = new JTable(); this.table.setShowGrid(false); this.table.getTableHeader().setFont(ReportViewConstants.TABLE_FONT); this.table.setFont(ReportViewConstants.TABLE_FONT); this.scrollPane = new JScrollPane(this.table); Dimension size = new Dimension(300, 400); this.scrollPane.setPreferredSize(size); this.scrollPane.setMinimumSize(size); this

Loading Java JTable: Why does it not work?

删除回忆录丶 提交于 2019-12-31 02:01:05
问题 I have created a simple GUI which includes a JTable. This table may be saved & loaded via the appropriate Object Stream. At this point the Save function is working as intended, and I can see the table object is stored in a file when looking in the save directory. However, when I try to load the table from the file, the GUI never displays the loaded table. The actionlistener function is called, as I have a system.out "Data loaded", but the table never displays updated data. I have tried to

How to word wrap inside a JTable row

北慕城南 提交于 2019-12-31 00:30:10
问题 I have a simple JTable that shows the details (in column format) of a row from another JTable. This works nicely. However, sometimes the text in a row is very long so the user ends up having to scroll across which isnt neat. How can I wrap the text in a row and allow the row height to change to show all the text in it. Here is the code: table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e

How do I get a JTable header to display entire column names instead of shortening them?

吃可爱长大的小学妹 提交于 2019-12-30 18:54:27
问题 I've a JTable that I fill with a class that extends AbstractTableModel. The problem is that the columns are too short to display the column name. I've turned off Jtable AutoResizeMode property, but shortening still occurs. How do I solve this? 回答1: Setting off autoresizemode only prevent the JTable's coumns to be resized. To force a particular width retrieve the table column model: TableColumn column = jtable.getColumnModel().getColumn(col_num); and set the desired width: column

how to search data in jtable using jtextfield?

五迷三道 提交于 2019-12-30 11:14:14
问题 I create jtable in netbeans and populate data from database in jtable, but i am unable to implement search option in jtable using jtextfield. Can anyone please guide me. Thanks 回答1: In order to search something on table you have to have original content stored in some variable.In the below example I stored the initial values of table model to a vector. There are two implementations below.One to search as soon as you type something on textfield, other to search only after a button is clicked.

Displaying JTable in JFrame

人盡茶涼 提交于 2019-12-30 10:34:38
问题 What i want to do: I want to list some records of a database. This list should be displayed in a JFrame popup. Description: I have 3 classes: Main.java (runs program) PeopleTableModel.java (holds data, extends AbstractTableModel) PeopleTable.java (holds logic, extends JTable) Why I am getting an ArrayIndexOutOfBoundsException when setting my JFrame to visible? Update: It seems like this error only shows up, when I use my own PeopleTable class. When I assign the table to just a normal JTable,

custom cell renderer for particular row and column

a 夏天 提交于 2019-12-30 10:33:53
问题 puuuuuuf, I'm starting to like swing :) I'm trying to write a cellRenderer to customy render all cells besides those which in first row and column. So I wrote the following: public class CustomTableCellRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object obj, boolean isSelected, boolean hasFocus, int row, int column) { Component cell = super.getTableCellRendererComponent(table, obj, isSelected, hasFocus, row, column); if(row >0&

Overriding JTable's DefaultTableCellRenderer to center all the cells in a JTable

蹲街弑〆低调 提交于 2019-12-30 10:30:28
问题 I've got a problem I can't get rid of. Just so you know, I'm fairly new to using JTables, so the answer might be simple, but I can't find a solution :/ So, I've got a JTable using an AbstractTableModel, which overrides the public Class<?> getColumnClass(int columnIndex_p) method, to tell the type of each column to be displayed. One of them is a Boolean. When I create a simple JTable, using table_l = new JTable(new MyTableModel()); everything is fine, and Boolean values are correctly displayed