how to print selected rows JTable

Seems to work okay for me… import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.print.PrinterException; import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.table.DefaultTableModel; import javax.swing.table.JTableHeader; public class TestPrint { public static void main(String[] args) { new TestPrint(); } public TestPrint() { EventQueue.invokeLater(new … Read more

How to gray-out non-editable cell in jtable?

Return an instance of GrayableCheckboxCellRenderer in a TableCellEditor. Addendum: Aesthetically, you may want to condition the renderer’s and editor’s colors based on the defaults provided by the current Look & Feel, for example: Color hilite = UIManager.getColor(“Table.selectionBackground”);

how to add checkbox and combobox in table cell?

Here is combo cell insets replicate demo: import java.awt.*; import java.awt.event.*; import java.util.EventObject; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; public class ComboCellInsetsDemo { public JComponent makeUI() { String[] columnNames = {“Name”, “Check”, “Condition”}; Object[][] data = { {“bbb”, false, “=”}, {“aaa”, true, “<“} }; DefaultTableModel model = new DefaultTableModel(data, columnNames) { @Override public Class<?> getColumnClass(int … Read more

How to set a custom object in a JTable row

Instead of splitting the User object up before you create the model, add it directly to the model and allow the model to do the work for you… For example public class VstTableItemModel extends AbstractTableModel { private List<User> users; public VstTableItemModel(List<User> users) { this.users = new ArrayList<User>(users); } @Override public int getRowCount() { return users.size(); … Read more

JTable Cell Renderer

Is your renderer ever even used? You make it the default renderer for cells containing String, but have you overloaded your model’s getColumnClass method so that it knows that some of the cells hold Strings? So first I’d use println statements to see if the renderer is even being called and if not, I’d override … Read more