jtable

How can I add custom JComponent in a single JTable cell?

元气小坏坏 提交于 2019-12-25 08:16:17
问题 I want to make a JTable , where one single cell (not all rows of a column) will contain a JComponent like JdatePicker or JComboBox . I have written this code DefaultTableModel dm; dm = new DefaultTableModel() { public boolean isCellEditable(int rowIndex, int columnIndex) { return !(columnIndex == 0); //make 0th column non-editable } }; Object [] columnHeaders=new Object[]{"Field", "Value"}; Object [][] data=new Object[][]{{"ID",""},{"Reg Year",""},{"Reg Date", ""}} ; regFormTable.setModel(dm)

Sorting different data types using setAutoCreateRowSorter in JTable

旧城冷巷雨未停 提交于 2019-12-25 07:58:51
问题 I am querying a MySQL database via Java, pulling data out of the result set and placing it in a DefaultTableModel, which gets put in a JTable, then into a JScrollPane to get displayed. In the JTable, I enable sorting in the table via table.setAutoCreateRowSorter(true); However, if the cells in the row I want to sort are not of class String, then I get a java.lang.ClassCastException. The data in my table has the following classes: java.sql.Date java.sql.Time java.lang.Double java.lang.Boolean

java timer countdown jtable

末鹿安然 提交于 2019-12-25 06:58:55
问题 I'm using this method to convert minutes into time (hh:mm:ss) public static String time(double m){ double t = m; int hours = (int)t / 60; int minutes = (int)t % 60; double seconds = (t - Math.floor(t)) * 60; System.out.println(seconds); if (seconds > 59){ seconds = 00; minutes++; } String myFormat = seconds >= 10 ? "%d:%02d:%.0f" : "%d:%02d:%.0f"; String time = String.format(myFormat, hours, minutes, seconds); return time; } the time will return as a string, then I will post it into a jTable,

Best practice Database Access - list of contacts

自古美人都是妖i 提交于 2019-12-25 06:23:53
问题 i have been wondering for a long time, whilst creating several stupid solutions for this Problem, how the following should be done properly: DataTable: ID | givenname | lastname | address | data ... I want to show all givennames + lastnames in a listbox and uppon selection of one item, i want to retrieve the rest of the corresponding dataset and display is in some textboxes. So i basically do: 1) Query: SELECT ID, givenname, lastname FROM DataTable; 2) Create and ArrayList of "Contact Objects

I have to add particular row from mysql to a JTable using a button

久未见 提交于 2019-12-25 05:53:54
问题 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { try { Class.forName("com.mysql.jdbc.Driver"); Connection con= (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/inventry","root",""); Statement stemt=con.createStatement(); String str = "select * from addproducts"; ResultSet rs = stemt.executeQuery(str); while(rs.next()) { model.addRow(new Object[]{rs.getString("pslno"),rs.getString("pid"),rs.getString("pname"),rs.getString("pcategory"),rs.getString(

Failed to looping in a jtable in JCCD API

旧巷老猫 提交于 2019-12-25 05:52:05
问题 I have build code clone application, that using JCCD API that impelemnted ANTLR. To show the code clone, I am using a jtable. This is my screenshot Application : https://docs.google.com/file/d/0B_Rg--NnjJccMERpaTNidzR3cFE/edit?usp=sharing Okey, from the following screenshot above, I was success to compare one file to another one file. The problem is when I am compare a file to two or more files. The tables just give me the last suspect of code clone. But, in my netbeans output console, I was

Failed to looping in a jtable in JCCD API

孤街醉人 提交于 2019-12-25 05:51:29
问题 I have build code clone application, that using JCCD API that impelemnted ANTLR. To show the code clone, I am using a jtable. This is my screenshot Application : https://docs.google.com/file/d/0B_Rg--NnjJccMERpaTNidzR3cFE/edit?usp=sharing Okey, from the following screenshot above, I was success to compare one file to another one file. The problem is when I am compare a file to two or more files. The tables just give me the last suspect of code clone. But, in my netbeans output console, I was

Convert modelRowIndex to viewRowIndex for sorted JTable

那年仲夏 提交于 2019-12-25 05:30:31
问题 I have a sortable JTable; when a row is added I want to know its view -index. I tried using a table model listener like this: @Override public void tableChanged(TableModelEvent event) { if (event.getType() == TableModelEvent.INSERT) { int modelRowIndex = event.getFirstRow(); int viewRowIndex = table.convertRowIndexToView(modelRowIndex); System.out.println("viewRowIndex: " + viewRowIndex); } } This works if the table is not sorted. Unfortunately, if the table is sorted the conversion-method

How to make a scrollable JTable

て烟熏妆下的殇ゞ 提交于 2019-12-25 05:22:43
问题 Question 1) I have a JPanel ps, which has a null layout; a JScrolPane scrollPane, and a JTable table. I have added the table to the scrollPane, and then added the scrollPane to the Jpanel ps. The following is my code for doing that:- ps = new JPanel(); ps.setLayout(null); ps.setSize(1000,600); scrollPane = new JScrollPane(); scrollPane.setBounds(10, 119, 975, 300); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); ps.add(scrollPane); table = new JTable(data,

ArrayOutOfBoundException when getValueAt from a table that sets row filter

荒凉一梦 提交于 2019-12-25 04:58:18
问题 When i want to get a cell value from my table (after search with filtering) and select that row and execute the returnAction() , Exception occur. My code: public class BookPage_User extends JFrame implements ActionListener { private JButton returnBookBtn; private JTextField filterTF; private TableRowSorter sorter; private JTable table; private BookJDBC bookJDBC; private BookModel model; public BookPage_User(String[] enterUserInfo, String userId) { bookJDBC = new BookJDBC(); model = new