jtable

How I can use arraylist to store my data in predefined default table model for JTable

China☆狼群 提交于 2020-01-04 06:50:32
问题 I want to add data to my own JTable model in runtime. I have the table and add button on my interface. As I understand I cant do it with two dimensional array and want to use Arraylist in my custom made table model but I dont know how to make the constructor if I use such type of data. static String[] columnNames = {"A", "B", "C"}; static Object data[][] = new Object[15][3]; public MyTableModel() { super(data, columnNames); } this is the constructor for data as two dimansional array but I

Setting color in a row of a Jtable

筅森魡賤 提交于 2020-01-04 06:49:43
问题 I need help. I have two tables. In the instruction table., each row must be highlighted according to what instruction is being execute in the pipeline stages. Say for example., at time t10, I5 is in IS stage, so I5 in instruction table must be highlighted or the color of the row in instruction table must be change.say, I5 row is color red, I6 row is color pink, I7 is color green, I8 is color gray, I9 is color orange. I really need your expertise., thank you.. :) 回答1: Please try this using

JProgressBar in JTable problem

纵然是瞬间 提交于 2020-01-04 06:35:35
问题 I've got some problem, does anyone can help me ? Below is my code: public class Test { public static void main(String[] args) { Panel.panel.setVisible(true); } } class Panel extends JFrame implements Runnable { public static Panel panel = new Panel(); JButton b= new JButton("Start"); public Panel() { setLayout(new FlowLayout()); setSize(300,300); add(b); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { javax.swing.SwingUtilities.invokeLater(new Runnable(

Expanding JTable Inside JFrame

会有一股神秘感。 提交于 2020-01-04 05:29:18
问题 I have the following layout that looks like this: But I would like the table at the top to be minimized to just the headers, then grow vertically as clients are added. How do I go about doing this? Here is the code currently...... JFrame frame; JTable clientTable; DefaultTableModel clientTableModel; JTextArea messageArea; ... String[] tableColumnNames = ... Object[][] data = ... Toolkit toolkit = Toolkit.getDefaultToolkit (); Dimension dim = toolkit.getScreenSize(); frame = new JFrame("Server

Display Emoji character in JTable

懵懂的女人 提交于 2020-01-04 04:37:07
问题 I want to display loudspeaker character in a JTable : @Override public Object getValueAt(int row, int col) { switch (col) { [...] case 2: String symbol = "\uD83D\uDD0A"; return "State " + symbol; default: return ""; } } Unfortunaly i just see an square box. I'm not sure if i have to set an specific Font supporting this character or to apply an other encoding. For Googlers looking for a solution: I implemented a CustomRenderer for the JTable like @trashgod sugested. Examples are available here

Problems with JTable and JScrollpane size

点点圈 提交于 2020-01-04 04:15:24
问题 I have a JScrollPane with a JTable in it. In the JTable I have initially 3 rows. Later on rows get added. The default JTable with my 3 rows is ugly because JScrollPane calls getPreferredScrollableViewportSize from the client ( JTable ) and the return value is always the same. That's why my JTable / JScrollpane with 3 rows has this free space, JScrollpane and JTable do not have the same size. My solution is to make a subclass JTabl e, override getPreferredScrollableViewportSize and return in

Java, string instead of double after editing cell in TableModel

寵の児 提交于 2020-01-04 02:34:46
问题 I import a CSV file into a DefaultTableModel , one column is formatted as double, so far so good. But if I edit a cell from this column (double) in the JTable , after that this cell is no longer a double. Now it is a string. How can I change the type of the edited cell in the TableModel ? I know that I can parse a string to double with double value = Double.parseDouble(str); , but how can I ensure that this happens after editing a cell? Do I need a new TableModel -class like: class

Java, string instead of double after editing cell in TableModel

狂风中的少年 提交于 2020-01-04 02:34:05
问题 I import a CSV file into a DefaultTableModel , one column is formatted as double, so far so good. But if I edit a cell from this column (double) in the JTable , after that this cell is no longer a double. Now it is a string. How can I change the type of the edited cell in the TableModel ? I know that I can parse a string to double with double value = Double.parseDouble(str); , but how can I ensure that this happens after editing a cell? Do I need a new TableModel -class like: class

Java: break focus cycle in jtable

流过昼夜 提交于 2020-01-03 22:57:23
问题 In my JTable, I want to edit all relevant cells like in Excel. I implemented that ENTER stops editing the cell and transfers focus to the next cell. However, when I hit ENTER in the last cell, the focus cycle makes me jump to the fist cell. But I want to continue outside the table and set focus to a JButton. How can I break this cycle? 回答1: JTable is not a spreadsheet, but setCellSelectionEnabled() should allow you to proceed. Use setDefaultButton() as required, for example. Addendum: In

How to print out specific rows/columns of a JTable?

徘徊边缘 提交于 2020-01-03 04:23:29
问题 I am able to print a full JTable, but actually I would like more to print just a specific part of a JTable, for example from Row 10 to Row 50 and Column 70 to Column 150. How to do it ? 回答1: Get cell bounds for the selected fragment and calculate desired region ( Rectangle ), define clip region to paint only desired region, in the printable use Graphics's translate() method to shift the rendering. 回答2: I've faced this problem too. Solved by hiding columns before printing and restoring columns