Created
May 4, 2020 12:22
-
-
Save tychobrailleur/3bbde9442bfd2615049c1968723f6f3b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 DarkTableRendering 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 Class<?> getColumnClass(int columnIndex) { | |
return String.class; // force model to String | |
} | |
@Override | |
public int getRowCount() { | |
return rows; | |
} | |
@Override | |
public int getColumnCount() { | |
return cols; | |
} | |
@Override | |
public Object getValueAt(int rowIndex, int columnIndex) { | |
return "(" + rowIndex + ", " + columnIndex + ")"; | |
} | |
} | |
static class DarkTableCellRenderer extends DefaultTableCellRenderer { | |
@Override | |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, | |
boolean hasFocus, int row, int column) { | |
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); | |
this.setBorder(BorderFactory.createLineBorder(Color.GREEN, 2)); | |
return this; | |
} | |
} | |
public DarkTableRendering() { | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setTitle("Lorem Ipsum"); | |
try { | |
setSize(new Dimension(450, 300)); | |
JPanel mainPanel = new JPanel(); | |
JTable aTable = new JTable(); | |
aTable.setModel(new DarkTableModel(10,10)); | |
aTable.setDefaultRenderer(Object.class, new DarkTableCellRenderer()); | |
mainPanel.setLayout(new BorderLayout()); | |
mainPanel.add(new JScrollPane(aTable), 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 DarkTableRendering frame = new DarkTableRendering(); | |
frame.setVisible(true); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment