From 43e79778feb32ed34b85ff9a514767227b47fa33 Mon Sep 17 00:00:00 2001 From: Darkress <30271678+DarkressX@users.noreply.github.com> Date: Thu, 8 Jun 2023 02:15:37 +0200 Subject: [PATCH] Set column width --- de/darkress/pic16f84sim/Main.java | 10 +++++- de/darkress/pic16f84sim/gui/SramTable.java | 41 +++++++++++++--------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/de/darkress/pic16f84sim/Main.java b/de/darkress/pic16f84sim/Main.java index 442d860..703a03c 100644 --- a/de/darkress/pic16f84sim/Main.java +++ b/de/darkress/pic16f84sim/Main.java @@ -6,6 +6,7 @@ import de.darkress.pic16f84sim.gui.SramTable; import de.darkress.pic16f84sim.microcontroller.Memory; import de.darkress.pic16f84sim.microcontroller.ProgramCounter; +import javax.swing.*; import java.util.ArrayList; class Main @@ -21,6 +22,13 @@ class Main program.get(ProgramCounter.getPc()).execute(); } - SramTable.table(); + SramTable table = new SramTable(); + JFrame frame = new JFrame("Table Example"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.add(table.getTable()); + frame.pack(); + frame.setVisible(true); + //table.setValueAt("test", 15, 7); + } } \ No newline at end of file diff --git a/de/darkress/pic16f84sim/gui/SramTable.java b/de/darkress/pic16f84sim/gui/SramTable.java index 270d220..488e6b8 100644 --- a/de/darkress/pic16f84sim/gui/SramTable.java +++ b/de/darkress/pic16f84sim/gui/SramTable.java @@ -1,31 +1,45 @@ package de.darkress.pic16f84sim.gui; import javax.swing.*; +import java.awt.*; +import java.awt.geom.Dimension2D; public class SramTable { - public static void table() { - int rows = 16; - int columns = 8; + private final int rows = 32; + private final int columns = 8; + private Object[][] data = new Object[rows][columns]; + + public JTable getTable() + { + return table; + } + + private JTable table = new JTable(data, createColumns()); + + public SramTable() + { int count = 0; - // Create the data for the table - Object[][] data = new Object[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { - data[i][j] = count; + data[i][j] = Integer.toHexString(count).toUpperCase(); + table.getColumnModel().getColumn(j).setPreferredWidth(30); count++; } } + } - // Create the column names + private Object[] createColumns(){ Object[] columnNames = new Object[columns]; for (int j = 0; j < columns; j++) { - columnNames[j] = "Column " + (j + 1); + columnNames[j] = j; } + return columnNames; + } - // Create the JTable - JTable table = new JTable(data, columnNames); + + public void table() { // Create a scroll pane and add the table to it JScrollPane scrollPane = new JScrollPane(table); @@ -34,12 +48,5 @@ public class SramTable panel.add(scrollPane); // Create a frame and add the panel to it - JFrame frame = new JFrame("Table Example"); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.add(panel); - frame.pack(); - frame.setVisible(true); - - System.out.println(data[15][7]); } }