jtable

Why am I getting an ArrayIndexOutOfBoundsException when I delete JTable row?

廉价感情. 提交于 2019-12-24 00:28:32
问题 I am getting .ArrayIndexOutOfBoundsException when i try to delete a row from my JTable. Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Vector.elementData(Vector.java:734) at java.util.Vector.elementAt(Vector.java:477) at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:648) at Test$1.valueChanged(Test.java:34) at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184) at javax.swing

swing JTable with ScrollBar - color of square between headers and track

荒凉一梦 提交于 2019-12-24 00:01:02
问题 I have a JTable with BasicScrollBarUI, I set the headers background color: table.getTableHeader().setBackground(GuiConstants.backgroundColor); and the scrolbar background color: public class ScrollBarUI extends BasicScrollBarUI { @Override protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) { c.setBackground(GuiConstants.backgroundColor); } } I still have a square between them that its color won't change. does anybody knows how to change it also to their color? thanks

JSlider in JTable

此生再无相见时 提交于 2019-12-23 20:50:28
问题 For putting a JSlider into a JTable I wrote am AbstractCellEditor which implements a TableCellRenderer and a TableCellEditor . It gets initialized with values from 0 to 100. I have the strange behaviour that when I first click onta a slider it jumps to the maximum. The second weird behaviour: I've added a ChangeListener . This Listener gets only called if I first click into the slider. A second click (which also changes the value) doesn't cause this event. Why? public class SliderTableColumn

JTable JComboBox wrong first item name

穿精又带淫゛_ 提交于 2019-12-23 20:15:25
问题 I added a Swing JComboBox to a JTable , but the label of my first item is always javax.swing.JComboBox(... What am I doing wrong? UPDATE : this is my code : import java.awt.Color; import java.awt.Dimension; import java.util.ArrayList; import javax.swing.DefaultCellEditor; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel;

JTable TableCellRenderer background with NimbusLookAndFeel color problem

时间秒杀一切 提交于 2019-12-23 18:52:06
问题 I'm using NimbusLookAndFeel. With this look and feel JTable's cell background are alternatively white and light grey (it depends on the row number). Now, I'm writing some custom cell renderer implementing TableCellRenderer. I need to set the background of these renderers according to the position of the cell in the JTable. public class MyCellRenderer extends JLabel implements TableCellRenderer{ @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean

JTable Headlines between rows

烂漫一生 提交于 2019-12-23 18:38:33
问题 I am wondering how I can realize something like this: row 1 row 2 HEADLINE like 27.01.2011 row 3 row 4 HEADLINE like 28.01.2011 row 5 These "fake" rows should be only information-rows and not real rows. I couldn't find something like that. I hope you understand my problem. Thanks for pointing me in the right direction! 回答1: I think that you have look at JTreeTable, JXTreeTable by SwingX, OutLine by NetBeans, nice workaround by aephyr and one non-free product by JideSoft EDIT 来源: https:/

Only one row editable on JTable

你说的曾经没有我的故事 提交于 2019-12-23 17:57:48
问题 I am trying to make a special kind of jtable. I want the entire table to by default be NOT editable. But when the user clicks a row, then clicks the "Edit" jbutton, that specific row is editable. and once they deslect the row its no longer editable. How would I go about doing this? 回答1: to control which cells are editable, you will need to extend either JTable or JTableModel (see the call to the model in the example below) to ensure that this method from JTable returns true for all the cells

How to hide Mac/OSX Drag and Drop JTable selection frame

ぃ、小莉子 提交于 2019-12-23 17:13:27
问题 When performing a drag and drop on a JTable there is an outline of the selected cell (selection frame) that appears while dragging. How can I override that behavior and not show anything but perhaps a special cursor? Running the following code in Windows and OSX shows the behavior I'd like to override! import java.awt.BorderLayout; import java.awt.dnd.DnDConstants; import java.awt.dnd.DragGestureEvent; import java.awt.dnd.DragGestureListener; import java.awt.dnd.DragSource; import java.awt

Using TableRowSorter with scala.swing.Table

早过忘川 提交于 2019-12-23 16:51:35
问题 I'm working on simple UI that has a scala.swing.Table component. I'd like to sort the table rows using java.swing.table.TableRowSorter. The Table class doesn't provide any API for using a row sorter so I tried setting it directly on the peer val table = new Table(height, width) { import javax.swing.table._ rowHeight = 25 autoResizeMode = Table.AutoResizeMode.NextColumn showGrid = true gridColor = new java.awt.Color(150, 150, 150) model = myModel peer.setRowSorter(new TableRowSorter(model)) }

Retrieve Data from MySQL DB and show in JTable

吃可爱长大的小学妹 提交于 2019-12-23 16:01:33
问题 I am using the following code for retrieving the data from MySQL Database. The code connects to the database properly. My problem is in retrieving the data from MySQL DB and showing it in the JTable. package student; import java.awt.*; import javax.swing.*; import java.awt.*; import java.sql.*; import java.util.*; import javax.swing.*; import java.awt.event.*; import javax.swing.table.*; public class student1 extends javax.swing.JFrame { // public Connection Conn; Vector data = new Vector() ;