Skip to content

Instantly share code, notes, and snippets.

@chrisvire
Created September 9, 2020 12:24
Show Gist options
  • Save chrisvire/c27c725595b9da76859fbfe3a874ddbf to your computer and use it in GitHub Desktop.
Save chrisvire/c27c725595b9da76859fbfe3a874ddbf to your computer and use it in GitHub Desktop.
JDK-8252965 crashes on macOS using OpenJDK 8.265.01.2
package org.sil;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
public class Main {
public static void main(String[] args) {
Main app = new Main();
app.buildAndDisplayGui();
}
private void buildAndDisplayGui() {
JFrame frame = new JFrame("Test");
buildContent(frame);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
private void buildContent(JFrame frame) {
JPanel panel = new JPanel();
JTable table = new JTable();
String[] columnNames = new String[2];
columnNames[0] = "Book Id";
columnNames[1] = "Book Name";
DefaultTableModel model = new DefaultTableModel(columnNames, 2);
table.setModel(model);
// This works
addRow(model, table.getFont(), "1", "Test");
// This crashes
addRow(model, table.getFont(), "2", "പത്രൊസ്");
updateRowHeights(table);
panel.add(table);
frame.getContentPane().add(panel);
}
private void addRow(DefaultTableModel model, Font font, String bookId, String bookName) {
Object[] columns = new Object[2];
columns[0] = bookId;
if (font.canDisplayUpTo(bookName) < 0) {
columns[1] = bookName;
} else {
columns[1] = "Fail";
}
model.addRow(columns);
}
private void updateRowHeights(JTable table)
{
try {
for (int row = 0; row < table.getRowCount(); row++) {
int rowHeight = table.getRowHeight();
for (int column = 0; column < table.getColumnCount(); column++) {
Component comp = table.prepareRenderer(table.getCellRenderer(row, column), row, column);
rowHeight = Math.max(rowHeight, comp.getPreferredSize().height);
}
table.setRowHeight(row, rowHeight);
}
}
catch(ClassCastException e) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment