jtable

How to refresh a JTable after database operations without frame reload?

戏子无情 提交于 2019-12-23 05:11:10
问题 I want to refresh a JTable after performing db operations like insert/update/delete without frame reload. Is there a programmatic solution to do so? 回答1: The answer depends on what type of TableModel you're using...and at what level the events are occuring. For example, if you have some kind of background Thread or "update" button and want to reload the content from the database, simple create a new TableModel based on the results from the database and apply it to the current JTable , this

JTable setValueAt StackOverflowError

前提是你 提交于 2019-12-23 05:08:48
问题 I've been searching for whole day and I still can't find simple anwser to my problem: how can I make JTable cell update it's value when I edit it in another one? I wanted to use somehow fireTableCellUpdated but I don't really understand how can I use it, when and on what object. What I want is to obtain is some kind of listener that listens whether that values changes or not. In this particular scenario I have editable third column in which I store the amount and I want that listener to

How to export a JTable to a .csv file?

自作多情 提交于 2019-12-23 05:04:39
问题 Like the title implies, i am looking for a way to export a jtable with data to a .csv file . I am not looking for other options then CSV , because CSV is the requirement for my program. I have been looking at certain things, like bindy of apache.camel put I couldn't find enough information to understand how to use it. What is recommended? If someone has a decent example of the usage of bindy I wouldn't mind either. Friendly regards, Skillcoil 回答1: You can use apache poi to generate an Excel

Jtable with conditional formatting like Excel

无人久伴 提交于 2019-12-23 04:58:20
问题 Does JTable supports 3 color conditional formatting like excel does. Example: I checked on google and all I could find assigning single color at a time to a cell which matches the criteria. I was wondering if I could just provide three colors and Jtable would assign shades of color according to the value of the cell. 回答1: Here is one of the ways, how you can do this. Additional classes we can find here . import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension;

Is there a way to put an ArrayList into a JTable where each line is the next index of the ArrayList?

别来无恙 提交于 2019-12-23 04:54:44
问题 I have many different array lists. I want each index to be a new row in the JTable but I'm not sure how to do that. I made a for loop but it is not working. Is there even a way to populate a JTable with an array list and not an array? public TableCreator() { super(new GridLayout(1,0)); String[] columnNames = {"Item Type", "Description", "Size", "Price"}; // for(int i=0; i<ShoppingFunctions.cartType.size(); i++){ for(int i=0; i<GUI.size.size(); i++){//FIX!!!! item = ShoppingFunctions.cartType

How to color specific rows in a JTable

霸气de小男生 提交于 2019-12-23 04:52:07
问题 I want the ability to highlight some rows of JTable , depending on the values in the row itself. For example, if the existing qty < reorder level , that row should be highlighted in the JTable . I know there is a table method tblItems.setSelectionBackground(Color.yellow); that works when the rows are selected, but is there a similar method that doesn't rely on the rows being selected to have them show in a different color? public class MyTableCellRenderer implements TableCellRenderer {

Java JTable sort with TableCellRenderer

旧巷老猫 提交于 2019-12-23 03:28:07
问题 I'm somewhat new to Java and I'm having problems with JTable with sort and TableCellRenderer . I have a table with 15 columns populated with values where on some columns I use the TableCellRenderer to change the color of foreground to green or red acording the values on the cell. Everything is working perfectly until I try to sort by some column (the sorting part is ok)... The problem is that the formating colors don't reflect the change made by the sort operation. The colors stay unchanged

JTable use Row Numbers?

怎甘沉沦 提交于 2019-12-22 18:39:00
问题 I am creating a program to work like Microsoft Excel , in JAVA. My problem is how do I put the row numbers beside each row of the JTable ? I have seen it working in other Java Programs - I just can not figure out how to include it in mine. Google gave me this website, and apparently it works. When I use it in my program this nothing happen. :/ I there a better way of adding row numbers in a JTable ? I have looked at the Java Tutorials already. I am sorry if this question has been asked before

Please help me to allow my `JTable` to search the text even the table is in editable mode on key-press

▼魔方 西西 提交于 2019-12-22 18:25:26
问题 If user starts pressing keys using keyboards then JTable is supposed to be searched the matching text for him and if user double clicks on cell then Table should allow him to edit the text. And the issue is - Table is only searching text when the table is in non-editable mode and if Table is editable and user starts typing the text-using keyboard, cell is allowing him to edit the cell rather then search. Mr mKorbel has just solved my issue to allow edit only if double click on Table cell.

Select all data when start editing JTable Cell

元气小坏坏 提交于 2019-12-22 17:49:33
问题 I'm trying to make a table that works like Excel. Meaning, when a user starts to insert data into the cells the content into them is selected and changed by the new data inserted. 回答1: You can create a custom TableCellEditor for your table. This class will have an instance variable of a TextField , lets call it textField . Then the getTableCellEditorComponent method could look like this: public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int