jtable

JTable CustomRenderer Issue

♀尐吖头ヾ 提交于 2019-12-24 11:10:51
问题 I have created one Jtable.This table consist of two columns name and timestamp. I want to make color of row yellow if name is "jane". Following is the code for that :- class CustomRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); String name = table.getModel()

java.math.BigDecimal cannot be cast to java.lang.String?

不打扰是莪最后的温柔 提交于 2019-12-24 11:03:14
问题 I am trying to add row values of datatype(money) in which zeros after decimal are automatically formed in Jtable like these 55.0000 28.0000 60.0000 20.0000 50.0000 on runtime log showing this error java.math.BigDecimal cannot be cast to java.lang.String Here is the code for rows addition from Jtable double total = 0; for(int i = 0; i<table.getRowCount(); i++){ double amount = Double.parseDouble((String) table.getValueAt(1, 6) ); total+=amount; } totalSum.setText(String.valueOf(total)); * Is

Unreported exception SQLException; must be caught or declared to be thrown error

落爺英雄遲暮 提交于 2019-12-24 10:56:16
问题 This allows me to grab data from my database, store it as a DefaultTableModel and pass that model onto my GUI - populating my jTable with database data. This is the method within my Account class: public static DefaultTableModel buildTableModel() throws SQLException { Vector<Vector<Object>> data = new Vector<Vector<Object>>(); Vector columns = new Vector(); PreparedStatement ps = null; ResultSet rs = null; try { String stmt = "SELECT * FROM APP.DATAVAULT"; ps = Main.getPreparedStatement(stmt)

How to make JTable show refreshed data after updating database?

ぃ、小莉子 提交于 2019-12-24 10:49:24
问题 I have updated a database and I would like to refresh a JTable with this code tied to a button click event, but it doesn't work. When I close aplication and open it again JTable shows the right data. Do I need to override some method on my abstract table? try { model=new MyTableModel(this.database); table = new JTable(model); } catch (SQLException e) { e.printStackTrace(); } scrollPane = new JScrollPane(table); refresh.addActionListener(new ActionListener() { public void actionPerformed

JTable Checkbox should start timer when checked

故事扮演 提交于 2019-12-24 10:07:18
问题 I am looking to have a column in a JTable that counts the time that boolean column in the table is 'true' for. It is a timer for how the long the checkbox is checked. I'm having trouble wrapping my head around all of the mechanics for the algorithm. ActionListener actListner = new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("k"); aTable.updateTime(); } }; Timer timer = new Timer(1000, actListner); timer.start(); TableModelListener tableListener = new

Inserting text alongside a checkbox in a Jtable cell

99封情书 提交于 2019-12-24 09:50:07
问题 I have been fiddling around with this for a while, and all the solutions and working examples I could find included check boxes rendered using the built-in Boolean TableCellRenderers, that is a cell could have only a check box. I didn't find any working example where there would be some text alongside that check box in that SAME cell, or more specifically a JCheckBox which allows a check box and a text. 回答1: When your data/requirements doesn't fit within the default available functionality,

JTable refreshing

本小妞迷上赌 提交于 2019-12-24 09:49:27
问题 I use JTable with horizontal and vertical scrollbars. My JTable has empty space after rows with data. When I open panel that is situated down of my table it hides a part of JTable and scrolling appears on JTable. This is normal behavior, but then I close that panel, empty space without data becomes grey instead of white color. This only happens when I have horizontal scrollbar on my JTable. I suppose I must force JTable to repaint, I tried resizeAndRepaint() on TableHeader and JTable but it

How to get full highlighting (with border) on JTable Renderer

此生再无相见时 提交于 2019-12-24 09:33:01
问题 There is a common method when using JTable TableCellRenderers for setting the background and foreground when the cell is selected. Here is an example question that was asked: Why does my Java custom cell renderer not show highlighting when the row/cell is selected? This solution is lacking one thing ... the border around the cell. (Note I am not asking about a border around the row, as was asked here.) The border should highlight when the cell is selected. It is not acceptable to just create

JTable and Look and Feels

空扰寡人 提交于 2019-12-24 08:24:21
问题 I have small problem with changing look and feel of an object. In my app I have public class JavaCommander extends JFrame and in this class I have JTable that is constructed with my own table model. Everything works fine, but as I said there is a problem when I want to change look and feel. In menu bar I have a menu with available look and feels. menuBar=new JMenuBar(); JMenu lookMenu=new JMenu("Look and Feel"); UIManager.LookAndFeelInfo[] info= UIManager.getInstalledLookAndFeels();

Java Swing: Showing tool tip in JTable based on text under mouse pointer

我的梦境 提交于 2019-12-24 08:14:18
问题 I have a JTable where I display some string data formatted using html. I need to show a tool tip based on the text under the mouse pointer On mouse over "Line1" and "Line2" I need to show different tool tips. Is there any way to achieve this or do I have to use a custom renderer to render each line with a cell and show tool tip based on that ? Here's the sample code to create the table package com.sample.table; import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event