-
-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FlatLaf causes ArrayIndexOutOfBoundsException ONLY on Linux #532
Comments
The exception occurs when you drag a column, right? Could you please set a breakpoint at following line |
Actually I am not dragging. The exception occurs when a popup menu is shown over the table headers and I trigger an update to the table model. Our code is really old and deletes and creates the columns during this process on the fly. It might rearrange columns during that process as well. That might be the reason why the index might become -1 during the process. But as I have written this exception only occurs on linux. I will try debugging tonight. |
@DevCharly So I finally managed to debug on macOS, Linux and Windows. |
Using Nimbus LaF |
I've following theory: If you show a popup menu on column click, then the table header probably not receives the mouse-released event, and But don't understand that it happens only on Linux. Any why not on Windows and macOS or in Nimbus? Will try to reproduce this. BTW How do you show the popup menu? Do you use a mouse listener? On pressed or on released? |
Ok, the theory from my previous post is correct. Occurs in any look and feel and probably in any Java version (tried 8 and 18), Run following app, right-click on table header and select the "fireTableStructureChanged" menu item immediately throws the exception. import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import com.formdev.flatlaf.FlatLightLaf;
public class TableHeaderTest
{
public static void main( String[] args ) {
SwingUtilities.invokeLater( () -> {
FlatLightLaf.setup();
JTable table = new JTable( new Object[][] {
{ "abc", "def" }
}, new Object[] { "Col A", "Col B" } );
JMenuItem mi = new JMenuItem( "fireTableStructureChanged" );
mi.addActionListener( e -> {
((AbstractTableModel)table.getModel()).fireTableStructureChanged();
} );
JPopupMenu pm = new JPopupMenu();
pm.add( mi );
table.getTableHeader().setComponentPopupMenu( pm );
JOptionPane.showMessageDialog( null, new JScrollPane( table ) );
} );
}
} |
…ving column) from a table header popup menu action (issue #532)
I've added a workaround to avoid the exception. See commit 6c18431 If you support other Lafs (e.g. Nimbus) in your application, then you should consider to clear dragged column in those actions that change table structure from table header popup menu. E.g. table1.getTableHeader().setDraggedColumn( null ); |
I am intending to solely change to FlatLaf and support for other LaF will be eliminated. |
|
macOS and Windows still work as expected. I would consider the issue fixed. Do you want me to close it? Thank you very much! |
Great 😄 |
The issue only appeared on Linux because different platforms have different popup triggers - in Linux the popup menu is triggered by the mouse pressed event - so the draggedColumn is still set to a column that is probably no longer valid - and in Windows (and MacOS, I suppose) by mouse released, so after the dragged column is changed to null. |
@mchmaj thanks for the info. This solves the mysterry 😄 Didn't know that. |
I tried migrating my existing Java app to FlatLaf. It works perfect on macOS and Windows, but I can repeatedly produce the following exception on various Linux versions with X11 or Wayland:
I cannot reproduce this error both with Metal or Nimbus L&F therefore I guess it is caused somewhere within FlatLaf.
I tested FlatLaf versions 2.2,2.1,2.0 and all produce the exception using Java 17 on Linux.
The text was updated successfully, but these errors were encountered: