jtable

Java JTable: Setting a primary column to always sort by first

你。 提交于 2019-12-24 04:19:10
问题 I'm using a JTable with say 3 columns, displaying information about files and folders: Col1: Either "file" or "folder" (String) Col2: Name of the file or folder (String) Col3: Creation date (Timstamp) I can easily sort the table by any column. But I'm not able to achieve the following desired behavior: No matter what column header the user clicks, folders should always display before files. So basically sorting by Col1 in any order other than descending should not be possible. Also, if sorted

JTable fails to sort Integers and Double values properly

喜夏-厌秋 提交于 2019-12-24 03:09:43
问题 I have read several questions about JTable sorting: Problems with JTable sorting of integer values JTable + Sorting specific field but I still can't manage to get it right, for some reason. I have written this: String allItemsColumns [] = { "#", "Name", "Stock", "Price", "Type", "Supplier", "Location", "" }; allItemsTableModel = new DefaultTableModel(null, allItemsColumns); allItemsTable = new JTable(allItemsTableModel) { Class<?>[] types = { Integer.class, String.class, Integer.class, Double

Check Boxes not able to be Selected — They are Editable! Java Swing

落花浮王杯 提交于 2019-12-24 02:47:10
问题 I have read so many questions on this website concerning this problem and I cannot find why it is still not working. The Problem: I made a JTable to be displayed inside a JScrollPane . The JTable is constructed as follows: table = new JTable(new DataTableModel()); As you can see, I use a custom AbstractDataModel called DataTableModel . Now, when I display this the checkboxes appear, but they are not able to be selected . They are editable as you can see below. Here is the pertinent code in

how to highlight multiple cells in jtable

人走茶凉 提交于 2019-12-24 02:44:18
问题 I have to search text in jtable data. e.g. "ADMIN" text is appearing multiple places in jtable then how to highlight all the cells that contains specified value. Does anyone have any idea ? 回答1: As @kleopatra suggested, use a custom CellRenderer (the following example is just a POC, add methods to change the search pattern, highlight color, etc.): import java.awt.Color; import java.awt.Component; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import

Need to add JCheckBox In JTable Dynamically

陌路散爱 提交于 2019-12-24 02:31:18
问题 I have two JTable . There are certain number of records in one JTable . Once the first JTable is loaded I want to load equal number of JCheckbox to be created in the second table. I have this scenario ... vl pass both the tables in method addCheckBox . private void addCheckBox(JTable procTableSrc, JTable procTableCk){ CheckBoxRenderer checkBoxRenderer = new CheckBoxRenderer(); EachRowRenderer rowRenderer = new EachRowRenderer(); int rows = procTableSrc.getRowCount(); DefaultTableModel dm =

JTable - compound editor focus

穿精又带淫゛_ 提交于 2019-12-24 01:56:30
问题 I have a custom editor composed of several components. Something like: class MyCellEditor extends AbstractCellEditor implements TableCellEditor { JTextArea textArea; JButton button; JPanel panel; MyCellEditor() { textArea = new JTextArea(); button = new JButton(); panel = new JPanel(new BorderLayout()); panel.add(textArea, BorderLayout.CENTER); panel.add(button, BorderLayout.EAST); } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int

JTable - compound editor focus

让人想犯罪 __ 提交于 2019-12-24 01:56:04
问题 I have a custom editor composed of several components. Something like: class MyCellEditor extends AbstractCellEditor implements TableCellEditor { JTextArea textArea; JButton button; JPanel panel; MyCellEditor() { textArea = new JTextArea(); button = new JButton(); panel = new JPanel(new BorderLayout()); panel.add(textArea, BorderLayout.CENTER); panel.add(button, BorderLayout.EAST); } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int

Inserting new data from External class into Jtable

本小妞迷上赌 提交于 2019-12-24 01:52:48
问题 i am new to Stack overflow and looking for some help on a java app i have been working on at college. My questions is, how do I insert an integer from a Jtextfield (in external class) into a Jtable using a button action listener event. My code is: External class Button Code to insert a jtextfield integer to the table package banknew; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing

How to add rows to JTable with AbstractTableModel method?

烂漫一生 提交于 2019-12-24 01:25:43
问题 I want to add rows to an already initialized JTable. Apart from other elements I have the following (relevant) code: import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; class sscce extends JFrame { private static final long serialVersionUID = 1L; // Serial

JTable select multiple non-contiguous cells with ctrl+click combination

拈花ヽ惹草 提交于 2019-12-24 01:05:10
问题 I want to create a JTable that I'll be able to select multiple, non-contiguous cells with ctrl+click combination. So far, when I select not contiguous cells from the same row it works fine. But when I select cells from different row, I get this Could somebofy please help me on this? Here's my code Class TestTimeTable public class TestTimeTable extends JFrame{ private final int rows = 10; private final int cols = 8; private final String daysOfTheWeek[] = {"ΔΕΥΤΕΡΑ", "ΤΡΙΤΗ", "ΤΕΤΑΡΤΗ", "ΠΕΜΠΤΗ