Getting java.lang.ClassCastException when using "DefaultTableCellRenderer"
Answered
Hi,
I am using DefaultTableCellRenderer to cast my JTable cells and I get java.lang.ClassCastException. My plugin works fine on all the versions before 2019.2 . I get this error only in IntelliJ IDEA Community 2019.2. Please find the code and the error from below.
```((DefaultTableCellRenderer) scanResultsTable.getTableHeader().getDefaultRenderer())
.setHorizontalAlignment(SwingConstants.LEADING);```
Error:
```java.lang.ClassCastException: com.intellij.ui.table.JBTable$JBTableHeader$2 cannot be cast to javax.swing.table.DefaultTableCellRenderer```
Can someone please help me figure out what cause this issue since it is only occurs in IntelliJ Community 2019.2 .
Please sign in to leave a comment.
Hi!
Could you explain what is your plugin supposed to do?
At first sight it looks like you are trying to fix the header alignment for left-to-right languages, aren't you? In this case I suppose we'd better fix it in platform.
Default renderer for JBTable headers was changed (and no longer can be cast to the `DefaultTableCellRenderer` or `JComponent`).
You can update your code like this (it should work with all IDE versions):
Hi @Aleksey Pivovarov: Thanks for the reply. I will try this out.