Set column width
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user