jtable

Use custom TablecellRenderer in a JTable

こ雲淡風輕ζ 提交于 2019-12-20 05:38:10
问题 I am new to Java. I have created a JTable . This is how addRow method works when I try to add a row to the table. private void addTableRow(String type, String name, String rank, String notes, String location, Color color) { boolean isExport = isExportEnable(); tableModel.addRow(new Object[] { type, name, rank, notes, location, isExport }); } When adding the row I want to fill a different color for the column index 6. I created a custom table cell renderer. public Component

How to add JRadioButton to two columuns of a JTable and ButtonGroup them.

半城伤御伤魂 提交于 2019-12-20 05:31:13
问题 I want a JTable which consists of 2 columns(having RadioButton ) Active and Inactive such that if Active Column is Selected then Inactive RadioButton gets Unselected and Vice versa means that in a single row only 1 radiobutton can be selected out of 2 radiobuttons. the code for radiobutton is below . I am not able 2 add buttongroup for this 2 columns. public class NewJFrame extends javax.swing.JFrame { DefaultTableModel dt; public JRadioButton radioButton=new JRadioButton(); public class

How can to create a rollover effect in a JTable?

别来无恙 提交于 2019-12-20 05:15:34
问题 In my application, I'd like to create a rollover effect with the rows of a JTable. For example, when the mouse enters the row, the background color of that row will change; conversely, the color of that row will return to normal when the mouse exits that row. How can i do this? 回答1: Use the below code, which will give you an idea about applying rollover effect with rows of a JTable. import java.awt.Component; import java.awt.event.MouseEvent; import javax.swing.*; import javax.swing.event

highlight the cell in jtable

拈花ヽ惹草 提交于 2019-12-20 04:58:20
问题 I have this code fom stackoverflow how to highlight multiple cells in jtable : private static class CellHighlighterRenderer extends JLabel implements TableCellRenderer { public CellHighlighterRenderer() { setOpaque(true); // Or color won't be displayed! } @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { String val = (String)value; Color c; if (val.matches(".*MIN.*")) // Add a method to configure

Change/Update JTable content with JComboBox(category)

孤者浪人 提交于 2019-12-20 04:51:27
问题 I have a problem with my JTable. My JTable displays content of a database. One database table has the name category. Every category is displayed in the JComboBox. If I click on a category it should update the table content. Here is a short snipped of my code for you, so it is easier to help me. The code should be runable: (TestClass - Main) package test; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import

Different imageIcon in different cells in JTable

大城市里の小女人 提交于 2019-12-20 04:29:04
问题 I think I got the imageIcon to show up differently in each cell but for some reason when I compile it, the images don't show up. It displays the name of the image but the image itself doesn't show up. Here is an image. http://i49.tinypic.com/r9ibrn.jpg public class movies extends JFrame { public movies() { initComponents(); } private void initComponents() { panel = new JPanel(); logo = new JLabel(); pane = new JScrollPane(); setDefaultCloseOperation(EXIT_ON_CLOSE); setBackground(new Color(255

Change the color of specific rows in my JTable

夙愿已清 提交于 2019-12-20 03:56:06
问题 I am looking for how to change the color of some rows in my JTable which have index in an integer vector called Notfoundrow , but the problem that I have as result all the rows in the Table change color to Red !! Here is my code : package essai_trafficclass; import java.awt.Color; import java.awt.Component; import java.util.ArrayList; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; public class MonCellRenderer extends DefaultTableCellRenderer { public static

Java Swing, Trying to replace boolean check-box in a JTable with an image-icon checkbox

喜你入骨 提交于 2019-12-20 03:21:40
问题 So I have a JTable with check-boxes. I would like to have the check-boxes contain one image when they are "checked" and another image when they are "unchecked" (i.e., display images instead of a checked or unchecked box). Is there a way to do this? I've tried fooling with the TableCellRenderer that returns a JLabel with an ImageIcon but it was not really very effective. More specifically, when the box is checked or unchecked the right images are there, but when the user is changing the check

Java JTable - show rows only which matches the string

跟風遠走 提交于 2019-12-20 03:19:09
问题 I have a JTable populated with data from a database. I have added a search function that display the rows, if word matched to some rows when the data is typed into a JTextField . But at the minute as you type a string or word that do not matches any of the rows data, what I want to do is to hide all the rows, and the JTable will show just the column names. Just like when something matches IT, shows those rows only which has the string that user typed and hide others. Here is my code that I am

How to make one mySQL's table column invisible

我怕爱的太早我们不能终老 提交于 2019-12-20 03:05:33
问题 I am running a query on ID column but I don't want it to be visible in my frame/pane. How can I achieve this? Shall I make another table, is there a function in sql/mysql which allows to hide columns? I tried to google it but havent found anything yet. Here is the code: public void tableChanged(TableModelEvent e) { int row = e.getFirstRow(); int col = e.getColumn(); model = (MyTableModel) e.getSource(); String stulpPav = model.getColumnName(col); Object data = model.getValueAt(row, col);