Reputation: 3427
The Table won't show in the window. Theres an outline, but no grid! Please help!
tetris.java
package com.diesal11;
import com.diesal11.Board;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
public class Tetris extends JFrame{
private static final long serialVersionUID = 1L;
public Tetris() {
this.setSize(200, 400);
// this.setResizable(false);
this.setTitle("Tetris");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
Board board = new Board(this);
JScrollPane ScrollPane = new JScrollPane(board);
this.add(ScrollPane, BorderLayout.CENTER);
}
public static void main(String[] args) {
Tetris game = new Tetris();
game.setLocationRelativeTo(null);
game.setVisible(true);
}
}
Board.java
package com.diesal11;
import javax.swing.JPanel;
import javax.swing.JTable;
public class Board extends JPanel{
private static final long serialVersionUID = 1L;
Tetris parent;
int BoardWidth = 10;
int BoardHeight = 20;
JTable Table;
public Board(Tetris parent){
// setFocusable(true);
this.parent = parent;
this.Table = new JTable(this.BoardWidth, this.BoardHeight);
this.Table.setValueAt("aaa", 0, 0);
this.Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
this.Table.getColumnModel().getColumn(1).setHeaderValue("Test");
}
}
Thanks in advance! Im new to Java so Apologies if it's something really simple!
Upvotes: 0
Views: 3827
Reputation: 137362
You should add the table to the jpanel:
....
this.Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
this.Table.getColumnModel().getColumn(1).setHeaderValue("Test");
this.add(Table);
Also, the convention is to start variable names with lower case letter.
Upvotes: 3