jtable

How to restore column widths in a JTable?

强颜欢笑 提交于 2021-01-29 00:34:49
问题 My question is clear. Is there any way to restore the width of the columns automatically after user has resized them? Every time the button is clicked, I want the column widths to be restored. public class TableTest { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame(""); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); JTable table = new JTable(new Object[][] { { "something", "something else" } },

Delete row from JTable

北慕城南 提交于 2021-01-28 14:50:44
问题 I need to remove row from JTable. Here is my code : import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import java.awt.GridLayout; import javax.swing.JPanel; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame;

Changing the color of a JTable cell DYNAMICALLY

独自空忆成欢 提交于 2021-01-28 08:58:20
问题 I would like to know how do i change the background color of a cell in a Table without any response from users. For example, if there is a change in one of my variables due to some unrelated method calls, which I would like for to be reflected in my table. Example, a method changes a value of my array that I used to initialize my table, however the user had no hand in it, like say a elapsed time change in value. So how do I reflect it on my table, or is there any way I could manually call the

Changing the color of a JTable cell DYNAMICALLY

天大地大妈咪最大 提交于 2021-01-28 08:41:38
问题 I would like to know how do i change the background color of a cell in a Table without any response from users. For example, if there is a change in one of my variables due to some unrelated method calls, which I would like for to be reflected in my table. Example, a method changes a value of my array that I used to initialize my table, however the user had no hand in it, like say a elapsed time change in value. So how do I reflect it on my table, or is there any way I could manually call the

Creating bold cell border lines JTable

有些话、适合烂在心里 提交于 2021-01-28 06:40:56
问题 I'm trying to create a Sudoku game and I am having trouble creating the bold lines to break it into 3 x 3 blocks. My recent attempt was to impose an image on top of the table using JLabel . The problem is the label completely covers the JTable . I goofed around with setting the opacity of the label and the table with no luck. Here are some images to show what I'm aiming for: The current look: The goal: If you could advise me as to a method I can use to create these lines, it would be greatly

How can I move a table downward in Java?

元气小坏坏 提交于 2021-01-20 09:03:08
问题 Is it possible to move a table downward in Java. I tried setBorder , setLocation , ... but it didn't work. What should I do? JLabel label = new JLabel("Enter proper data: "); label.setBounds(0, 0, 120, 50); frame.add(label); JButton btn = new JButton("Click"); btn.setBounds(100, 300, 80, 50); frame.add(btn); String data [][] = new String [6][4]; String column[]={"No.","Player 1","Player 2","Strategy"}; JTable table = new JTable(data, column); JScrollPane sp=new JScrollPane(table); frame.add

How to insert/delete column to JTable java

不问归期 提交于 2021-01-20 04:13:34
问题 I have no ideas what to do. I am creating an application. I need to work with the table, so I am using JTable. But I have a lot problems with it. It seems to work, but when I try to delete column it this column disappears (only in GUI), but all the information still exists. Also columncount doesn't change. I have searched and tried a lot of different code, but nothing changed. public void addTblCol(JTable table,String name) { DefaultTableModel model = (DefaultTableModel)table.getModel();

How to insert/delete column to JTable java

别来无恙 提交于 2021-01-20 04:13:10
问题 I have no ideas what to do. I am creating an application. I need to work with the table, so I am using JTable. But I have a lot problems with it. It seems to work, but when I try to delete column it this column disappears (only in GUI), but all the information still exists. Also columncount doesn't change. I have searched and tried a lot of different code, but nothing changed. public void addTblCol(JTable table,String name) { DefaultTableModel model = (DefaultTableModel)table.getModel();

How to get a DefaultTableModel object's data into a subclass of DefaultTableModel

橙三吉。 提交于 2021-01-09 11:37:40
问题 I have a jTable displaying a simple two column sql table's data and allowing a user to maintain the list. This is my first java program. Have that working such that user can edit the list of data and press save to update. I get the sql data to the jTable's DefaultTableModel from this line of code: paCutAboveTable.SetTableModel((DefaultTableModel) DbUtils.resultSetToTableModel(rs)); I'm guessing DBUtils and resultSets are familiar to people here. I want to add a CheckBox to each row. Looking

How to get a DefaultTableModel object's data into a subclass of DefaultTableModel

六月ゝ 毕业季﹏ 提交于 2021-01-09 11:32:20
问题 I have a jTable displaying a simple two column sql table's data and allowing a user to maintain the list. This is my first java program. Have that working such that user can edit the list of data and press save to update. I get the sql data to the jTable's DefaultTableModel from this line of code: paCutAboveTable.SetTableModel((DefaultTableModel) DbUtils.resultSetToTableModel(rs)); I'm guessing DBUtils and resultSets are familiar to people here. I want to add a CheckBox to each row. Looking