Last active
May 4, 2020 10:08
-
-
Save tychobrailleur/621e82d08d2da2b5b3074da84a34b433 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.weblogism; | |
import com.github.weisj.darklaf.LafManager; | |
import com.github.weisj.darklaf.theme.DarculaTheme; | |
import javax.swing.*; | |
import javax.swing.table.*; | |
import java.awt.*; | |
public class DarkTable extends JFrame { | |
static class DarkTableModel extends AbstractTableModel { | |
int rows; | |
int cols; | |
public DarkTableModel(int rows, int cols) { | |
this.rows = rows; | |
this.cols = cols; | |
} | |
@Override | |
public int getRowCount() { | |
return rows; | |
} | |
@Override | |
public int getColumnCount() { | |
return cols; | |
} | |
@Override | |
public Object getValueAt(int rowIndex, int columnIndex) { | |
return "(" + rowIndex + ", " + columnIndex + ")"; | |
} | |
} | |
public DarkTable() { | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setTitle("Lorem Ipsum"); | |
try { | |
setSize(new Dimension(400, 300)); | |
JPanel mainPanel = new JPanel(); | |
// This doesn't work: | |
JTable aTable = new JTable(); | |
aTable.setModel(new DarkTableModel(10,10)); | |
// This works: | |
// JTable aTable = new JTable(new DarkTableModel(10,10)); | |
aTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); | |
JScrollPane scrollPane = new JScrollPane(aTable); | |
scrollPane.getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); | |
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); | |
mainPanel.setLayout(new BorderLayout()); | |
mainPanel.add(scrollPane, BorderLayout.CENTER); | |
getContentPane().setLayout(new BorderLayout()); | |
getContentPane().add(mainPanel, BorderLayout.CENTER); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public static void main(String[] args) { | |
SwingUtilities.invokeLater(() -> { | |
LafManager.install(new DarculaTheme()); | |
final DarkTable frame = new DarkTable(); | |
frame.setVisible(true); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment