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.Memory;
|
||||||
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
class Main
|
class Main
|
||||||
@@ -21,6 +22,13 @@ class Main
|
|||||||
program.get(ProgramCounter.getPc()).execute();
|
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;
|
package de.darkress.pic16f84sim.gui;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.geom.Dimension2D;
|
||||||
|
|
||||||
public class SramTable
|
public class SramTable
|
||||||
{
|
{
|
||||||
public static void table() {
|
private final int rows = 32;
|
||||||
int rows = 16;
|
private final int columns = 8;
|
||||||
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;
|
int count = 0;
|
||||||
// Create the data for the table
|
|
||||||
Object[][] data = new Object[rows][columns];
|
|
||||||
for (int i = 0; i < rows; i++) {
|
for (int i = 0; i < rows; i++) {
|
||||||
for (int j = 0; j < columns; j++) {
|
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++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the column names
|
|
||||||
Object[] columnNames = new Object[columns];
|
|
||||||
for (int j = 0; j < columns; j++) {
|
|
||||||
columnNames[j] = "Column " + (j + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the JTable
|
private Object[] createColumns(){
|
||||||
JTable table = new JTable(data, columnNames);
|
Object[] columnNames = new Object[columns];
|
||||||
|
for (int j = 0; j < columns; j++) {
|
||||||
|
columnNames[j] = j;
|
||||||
|
}
|
||||||
|
return columnNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void table() {
|
||||||
// Create a scroll pane and add the table to it
|
// Create a scroll pane and add the table to it
|
||||||
JScrollPane scrollPane = new JScrollPane(table);
|
JScrollPane scrollPane = new JScrollPane(table);
|
||||||
|
|
||||||
@@ -34,12 +48,5 @@ public class SramTable
|
|||||||
panel.add(scrollPane);
|
panel.add(scrollPane);
|
||||||
|
|
||||||
// Create a frame and add the panel to it
|
// 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