Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #18877
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2012-09-21 07:57 -0700 |
| Message-ID | <e4bc8305-301d-461e-a218-5c0529c1cc67@googlegroups.com> (permalink) |
| Subject | CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean |
| From | clusardi2k@aol.com |
Hello, I have discovered a hidden error. My project was working for awhile, but then I started to get the below error.
My error comes from the fact that I'm using a checkbox in a jtable, and I'm using the below "getColumnClass".
Thank you,
compile:
run:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at javax.swing.JTable$BooleanRenderer.getTableCellRendererComponent(JTable.java:5412)
at javax.swing.JTable.prepareRenderer(JTable.java:5735)
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2114)
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:2016)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1812)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:161)
at javax.swing.JComponent.paintComponent(JComponent.java:778)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5221)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1482)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1413)
at javax.swing.RepaintManager.paint(RepaintManager.java:1206)
at javax.swing.JComponent._paintImmediately(JComponent.java:5169)
at javax.swing.JComponent.paintImmediately(JComponent.java:4980)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:770)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:728)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:677)
at javax.swing.RepaintManager.access$700(RepaintManager.java:59)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1621)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:701)
at java.awt.EventQueue.access$000(EventQueue.java:102)
at java.awt.EventQueue$3.run(EventQueue.java:662)
at java.awt.EventQueue$3.run(EventQueue.java:660)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:671)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
--------
The below project runs perfectly. Without seeing my large project, how can I modify the below project to get my other large project to work.
package sorttable;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.util.ArrayList;
public class SortTable {
public static void main(String args[]) {
Runnable runner = new Runnable() {
public void run() {
JFrame frame = new JFrame("Sorting JTable");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Object rows[][] = {
{"VOD", "Vodafone Group", 26.02, new Boolean(false), new Boolean(false)},
{"SUNW", "Sun Microsystems", 3.86, new Boolean(true), new Boolean(false)},
{"EBAY", "eBay", 41.57, new Boolean(false), new Boolean(false)},
{"GOOG", "Google", 388.33, new Boolean(false), new Boolean(false)},
{"MSFT", "Microsoft", 26.56, new Boolean(true), new Boolean(false)},
{"NOK", "Nokia Corp", 17.13, new Boolean(false), new Boolean(false)},
{"ORCL", "Oracle Corp.", 12.52, new Boolean(true), new Boolean(false)},
{"TWX", "Time Warner", 17.66, new Boolean(false), new Boolean(false)},
{"AMZN", "Amazon", 41.28, new Boolean(false), new Boolean(false)},
{"YHOO", "Yahoo!", 37.69, new Boolean(false), new Boolean(false)}
};
String columns[] = {"Symbol", "Name", "Price", "OK", "Cheap"};
TableModel model =
new DefaultTableModel(rows, columns) {
public Class getColumnClass(int column) {
Class returnValue;
if ((column >= 0) && (column < getColumnCount())) {
returnValue = getValueAt(0, column).getClass();
} else {
returnValue = Object.class;
}
return returnValue;
}
};
JTable table = new JTable(model);
RowSorter<TableModel> sorter =
new TableRowSorter<TableModel>(model);
java.util.List sortKeys = new ArrayList();
sortKeys.add(new RowSorter.SortKey(3, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);
table.setRowSorter(sorter);
JScrollPane pane = new JScrollPane(table);
frame.add(pane, BorderLayout.CENTER);
frame.setSize(300, 150);
frame.setVisible(true);
}
};
EventQueue.invokeLater(runner);
}
}
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean clusardi2k@aol.com - 2012-09-21 07:57 -0700
Re: CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean clusardi2k@aol.com - 2012-09-21 08:01 -0700
Re: CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean clusardi2k@aol.com - 2012-09-21 08:32 -0700
Re: CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-21 11:57 -0400
Re: CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-09-21 10:31 -0700
Re: CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean clusardi2k@aol.com - 2012-09-21 11:43 -0700
Re: CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean Lew <lewbloch@gmail.com> - 2012-09-21 12:21 -0700
Re: CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean clusardi2k@aol.com - 2012-09-21 21:16 -0700
Re: CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean clusardi2k@aol.com - 2012-09-21 21:23 -0700
Re: CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean clusardi2k@aol.com - 2012-09-22 08:22 -0700
Re: CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean Stuart <DerTopper@web.de> - 2012-09-23 16:44 +0200
Re: CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean Lew <lewbloch@gmail.com> - 2012-09-21 10:32 -0700
Re: CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean Roedy Green <see_website@mindprod.com.invalid> - 2012-09-22 15:37 -0700
Re: CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean Roedy Green <see_website@mindprod.com.invalid> - 2012-09-22 15:30 -0700
csiph-web