jtable

How do I drag and drop a row in a JTable?

爷,独闯天下 提交于 2019-12-28 08:38:11
问题 How do you setup a JTable to be able to drag a row to a different index in the table. For example if I have 5 rows and I want to drag the 4th row to the 2nd position? 回答1: Check out the drag and drop section of the Java Tutorial. There are some examples on how to implement this for JTable . 回答2: The following allows JTable re-ordering of a single dragged row: table.setDragEnabled(true); table.setDropMode(DropMode.INSERT_ROWS); table.setTransferHandler(new TableRowTransferHandler(table)); Your

How to search subfolders and repaint a jTable with new data in Java?

泪湿孤枕 提交于 2019-12-28 07:09:13
问题 I'm having a couple problems with my program. I wanted a jTable to display various data points added to its TableModel, but I can't seem to get the table to update with the new data. Also, it seems my search for png images within a directory has fallen short of actually searching the directory completely for all png images and stops only at the first folder's contents. I've placed all data points into appropriate ArrayLists for their data types and converted them to Object arrays before

MessageFormat header/footerFormat how to change Font for JTable printing

假装没事ソ 提交于 2019-12-28 06:35:52
问题 in relation to this thread I have a question if someone to know if is possible to override/change larger font (Font Type, Size, Color) for MessageFormat headerFormat comings with JTable.PrintMode or I must paint g2.drawString("my header/footer") and JTable#print() separatelly 回答1: As everybody already mentioned (while I was relaxing in vacation :-) - TablePrintable is tightly knitted for secrecy, no way to subclass, no way to configure the header/footer printing. The only option to hook is to

Copying DefaultTableModel data to clipboard

做~自己de王妃 提交于 2019-12-28 04:35:12
问题 I have the next JTable private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(null); jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {"Hat", "New York", "1000"}, {"T-Shirt", "New York", "3500"}, {"Sweater", "Washington", "2800"}, {"Bag",

JTable Cell Renderer

删除回忆录丶 提交于 2019-12-28 04:09:05
问题 I'm following some code I found, (Yes I understand how it works) It's from here :Code Link What i'm trying to do is set a cells Foreground color if the cells value is set to "yellow" Here is my Code: public class Board extends JPanel{ private static final long serialVersionUID = 1L; int boardHeight = 20; int boardWidth = 10; JTable table; public Board() { table = new JTable(this.boardHeight, this.boardWidth); table.setDefaultRenderer(String.class, new BoardTableCellRenderer()); table

import csv to JTable

江枫思渺然 提交于 2019-12-28 03:05:08
问题 I have got a csv file and I want import it into a JTable. Is there a simple example showing how to import a csv file to JTable? 回答1: Use OpenCSV: CSVReader reader = new CSVReader(new FileReader("yourfile.csv")); List myEntries = reader.readAll(); JTable table = new JTable(myEntries.toArray()); 回答2: the last answer didn't work for me because JTable wanted an Object[][] and a String[] (of column names)... I had to do something like this: import com.opencsv.CSVReader; import java.util.List;

JTable enter key

一曲冷凌霜 提交于 2019-12-28 02:06:28
问题 I am developing an application using jTable for inventory management. The action is, by typing the item code in a jTextField and by pressing Enter key, the details of that code should come to jTable . And there I have to type the quantity and press Enter to calculate the amount. But now by giving item code the details come to the jTable , and I can type the quantity, but there by pressing Enter key jTable focus goes to the next row and no calculation is being done. But by again pressing Enter

JTable Multiple Header Rows

自古美人都是妖i 提交于 2019-12-28 02:05:18
问题 I am using a JTable in my application and wish to have 2 rows for headings, similar to this: Is this even possible or will I have to do something else? If so, what? Using Supertitle-titleA, SuperTitle-titleB will take up too much space and make information redundant. 回答1: We had the same requirement in our last project. What I have found is an Implementation for a GroupableTableHeader on java2s.com. However, I have pimped it a bit, although I cannot recall what exactly. Beneath is the

JTable won't show column headers

不羁岁月 提交于 2019-12-27 11:48:35
问题 I have the following code to instantiate a JTable: the table comes up with the right number of rows and columns, but there is no sign of the titles atop the columns. public Panel1() { int nmbrRows; setLayout(null); setBackground(Color.magenta); Vector colHdrs; //create column headers colHdrs = new Vector(10); colHdrs.addElement(new String("Ticker")); // more statements like the above to establish all col. titles nmbrRows = 25; DefaultTableModel tblModel = new DefaultTableModel(nmbrRows,

JTable with titled rows and columns

浪子不回头ぞ 提交于 2019-12-27 10:51:07
问题 How can I have a JTable with both columns & rows have title? something like this: +------+------+------+------+ |/\/\/\| col1 | col2 | col3 | +------+------+------+------+ | row1 | | | | +------+------+------+------+ | row2 | | | | +------+------+------+------+ | row3 | | | | +------+------+------+------+ Thanks 回答1: I think that you searching RowTable import java.awt.*; import java.awt.event.ActionEvent; import javax.swing.*; import javax.swing.UIManager.*; import javax.swing.event.*; import