jtable

Adding JTable to JScrollPane

China☆狼群 提交于 2020-01-16 01:54:05
问题 I have been making a small application containing JTable . The question is this: when I am adding the JTable to the JScrollPane , it is giving me the error that the table component is added to a parent component more than once. getContentPane().add(new JScrollPane(table)); scrollPane.setViewportView(table); I see the problem but could not solve it. Any suggestions? public thirdFrame() { thirdFrame = new JFrame(); thirdFrame.setFont(new Font("David", Font.BOLD, 17)); thirdFrame.setTitle(

How to change color of row in JTable

纵饮孤独 提交于 2020-01-15 12:21:46
问题 I want to change color of whole row in my JTable. I defined the JTable: JTable table = new JTable(data, columnNames); where data, columnNames are the String tables. The most common way to do this is to write own class: public class StatusColumnCellRenderer extends DefaultTableCellRenderer { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { //Cells are by default rendered as a JLabel. JLabel l =

JTable Sorting not Displaying Images

可紊 提交于 2020-01-15 11:43:58
问题 So I have successfully implemented a search feature into my tiny program but when I click the button to sort, it works fine but the images don't display. This is the code that I added for the sorter which works fine but the images for each row don't show up. When I take out this code, the images show up but the sorting doesn't work. Is there away that I can make the images show when sorting? // Sorter Code. Images show up when this code gets taken out. table = new JTable(model); final

JTable Sorting not Displaying Images

∥☆過路亽.° 提交于 2020-01-15 11:43:33
问题 So I have successfully implemented a search feature into my tiny program but when I click the button to sort, it works fine but the images don't display. This is the code that I added for the sorter which works fine but the images for each row don't show up. When I take out this code, the images show up but the sorting doesn't work. Is there away that I can make the images show when sorting? // Sorter Code. Images show up when this code gets taken out. table = new JTable(model); final

getTableCellRendererComponent is called over and over and makes 100% CPU usage

好久不见. 提交于 2020-01-15 09:28:25
问题 I have a JTable and one of its columns should display an image; I overrided getTableCellRendererComponent method of DefaultTableCellRenderer to do this. But the problem is while the image is not Null & cell is displaying it this method is called over & over (like it is called in an infinite loop) and uses 100% of CPU! (When the image is Null there is no problem!). What is the problem? My extended class is: public class imageCellRenderer extends DefaultTableCellRenderer{ @Override public void

Updating Data in a JTable

偶尔善良 提交于 2020-01-15 07:53:40
问题 Lets say I have a table. One of the cells holds a JLabel . If I change the text of the JLabel how do I get the JTable to show the change? Look at the following code, what should I change to make it show the changes to the JLabel ? public class ActivTimerFrame extends JFrame implements ActionListener{ //Data for table and Combo Box String timePlay = "1 Hour"; String timeDev = "2 Hours"; String[] comboChoices = {"Play Time", "Dev Time"}; String[] columnNames = {"Activity", "Time Allowed", "Time

How to auto-resize all columns of a JTable to the same size?

五迷三道 提交于 2020-01-15 07:35:48
问题 I'm using a JTable on a project. I want the table to auto-resize all columns to the same size, and at the same time, to fill the width of the containing JScrollPane. I can't just set a preferred width to a fixed value, because when the user will resize the frame, I want all the columns being resized to the same size, but with the constraint that it must still fill 100% of the JScrollPane. For instance, if the JScrollPane has a width of 1000, and I've got 10 columns, I'd like the columns to

How to access the data of each cell in a JTable

谁说胖子不能爱 提交于 2020-01-15 04:53:46
问题 I have used a tutorial to see how to implement JTable but I don't know how exactly access the data of each cell to extract the data that the user put in these. The table has 2 column and N rows In the first column there is a String in the second there is a int The tutorial that I have used is this 回答1: Every JTable has a data-model connected with it. Users may add data to this data model (e.g. by calling to the javax.swing.table.TableModel.setValueAt(Object, int, int) method) and JTable then

Netbeans: How do I add a valueChanged listener to a JTable from the “design” GUI builder?

折月煮酒 提交于 2020-01-14 19:29:11
问题 I right clicked the JTable and inserted some code into "post listeners code" in an awful kludge. I don't see an option to add table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { to "events" in the "design" view for the JTable. I'm sure there's a way to add a valueChanged(ListSelectionEvent evt) from design view, but how? maybe it's a bug? Row selection change events are produced by ListSelectionModel of JTable,

Deleting row from JTable after valueChanged event is triggered

感情迁移 提交于 2020-01-14 14:40:09
问题 I'm using ListSelectionListener to update my JTextField (countryTxt) from selected row. import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.table