jtable

JTable cell returning null

怎甘沉沦 提交于 2020-01-03 02:57:10
问题 I am using JTextField inside JTable cells; I use a TabelModel which has the dynamic data of the JTable . Now, when I click a button, I am reading a cell value. Problem is the cell which has the present focus doesn't return the updated value. For example, consider this program: import java.awt.BorderLayout; import java.awt.Component; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import

How to insert, update and delete items from JTable that is loaded from (SQLite) Database

孤街浪徒 提交于 2020-01-03 02:37:27
问题 I currently have 2 classes, one displaying the GUI and one is to get items from the database. My code is as follows: This code is to display the JTable in my GUI public void table() { if(SOMR.tableCall() == true) { this.columnNames = SOMR.getCol(); this.data = SOMR.getData(); JTable table = new JTable(data, columnNames) { public Class getColumnClass(int column) { for (int row = 0; row < getRowCount(); row++) { Object o = getValueAt(row, column); if (o != null) { return o.getClass(); } }

JTable Drag and Drop using TransferHandler

▼魔方 西西 提交于 2020-01-03 02:14:07
问题 Currently I am having two tables say Table-A, Table-B . My task is to drag rows from Table-A to Table-B or drag rows from Table-B on to itself. Using TransferHandler I have achieved this task. But my problem is, I am not able to recognize from which table row was dragged to Table-B .. i.e, either from Table-A to Table-B or from Table-B on to itself. In exportData method of TransferHandler I am adding some additional data to one of the column. Basing on this, when I am importing data through

Is there a generic TableModel we can use in JTables?

↘锁芯ラ 提交于 2020-01-03 01:22:28
问题 I'm now looking into JTables and have a bunch of business objects that I retrieve from the DB with Hibernate + Spring Data JPA. I love that Spring Data JPA handles all the cumbersome implementation of the DAL and was wondering if there's something similar for TableModel . Basically, I would have something along the lines of: public class GenericTableModel<T> extends AbstractTableModel And the GenericTableModel would use reflection and/or annotations to look into T . Does something like this

How do I add a JCheckBox to DefaultTableModel by adding a Boolean column?

二次信任 提交于 2020-01-02 20:17:14
问题 I am trying to add a jcheckbox to the first column of a JTable, which uses a DefaultTableModel . I tried returning a Boolean.class for that column, but it doesn't work. I already have a jcombobox in the last column, but using the same method I used to add that in order to add a jcheckbox doesn't work. I read online that java automatically returns a checkbox for you if you render a Boolean.class in a column, but using it also doesn't work. I think this might be a problem in the way I am

CellEditor with DocumentFilter never get called

强颜欢笑 提交于 2020-01-02 18:38:45
问题 I can't get this CellEditor with a DocumentFilter to work as i want. When i typed in the only editable column, insertString from PlainDocument is never called and documentFilter neither. I think im not overriding something correctly but i can't figured out. I made this Minimal, Complete, Tested and Readable example //TODO include imports public class Test { private static final int EDITABLE_COLUMN = 1; private final TableCellEditor cellEditor; private final JTextField textfield; private final

How to make Scroll pane static?

萝らか妹 提交于 2020-01-02 16:34:53
问题 Observation:: Whenever the user reaches the last cell in the table and press Tab key, the focus is shifted to the first cell i.e the top the table. Brought the table view back to the last cell, by using the function table.scrollRectToVisible(rect) , but due this there is movement and looks like there is a false change in the table values. The Scenario :: If I have make the make Scroll pane Static at particular position, so that I can control the movement. How can make this possible.. Thank

Create jTable with ArrayList

那年仲夏 提交于 2020-01-02 09:57:28
问题 I searched for a while but I cant find a solution for my problem. I want to display the Values of an ArrayList in a JTable, i'm pretty new to this and cant fix the error. package Statistik; import java.util.ArrayList; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; public class Statistic { private static ArrayList<String> rowA = new ArrayList(); private static ArrayList<String> rowB = new ArrayList(); private static ArrayList<String> rowC = new ArrayList(

How to Add a JXDatepicker for a JTable column

こ雲淡風輕ζ 提交于 2020-01-02 06:13:49
问题 I'm using a JTable. There I have a Date column, where I need to make a JXDatePicker appear when I click on a cell so that I can select a date from it. Can someone show me how to do this? Thanks! waiting for an answer.. 回答1: You should probably use DatePickerCellEditor , which is a CellEditor using a JXDatePicker as editor component. For example: TableColumn dateColumn = table.getColumnModel().getColumn(columnIndex); dateColumn.setCellEditor(new DatePickerCellEditor()); Here is a demo table:

Resizing JTable columns automatically based on text size

[亡魂溺海] 提交于 2020-01-02 05:21:12
问题 I have a JTable with some fields with long text and some with little text. By default, this is how it looks: Notice how the "Name" and "Title" rows are not shortened. I would like to know two things: How to manually set the width of Headers(Such as Name, Title, Surname) How to automatically resize all of them depending on the text. Here is the code: String[] columnNames = {"Name", "Title", "Surname", "ID"}; Object[][] testData = { {"John", "Mr.", "Doe", "61020384U"}, }; nameTable = new JTable