table java 不显示,java-无法显示JTable

我不知道出了什么问题.但是我稍微修改了您的代码(因为它存在编译时错误)

这对我来说可以.以下是屏幕截图

gnfTt.png

public class Item{

String itemDesc = "";

float price = 0;

Object[][] data = {{"test","test","test"},

{"test","test","test"},

{"test","test","test"},

{"test","test","test"}};

}

您的主表类

package test;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Menu;

import javax.swing.DefaultCellEditor;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.table.TableColumn;

public class Table extends JFrame

{

// Instance attributes used in this example

private JPanel topPanel;

private JTable table;

private JScrollPane scrollPane;

private JButton update_Button;

// Constructor of main frame

public Table() {

// Set the frame characteristics

setTitle("Add new item");

setSize(300, 200);

setBackground(Color.gray);

// Create a panel to hold all other components

topPanel = new JPanel();

topPanel.setLayout(new BorderLayout());

getContentPane().add(topPanel);

// Create columns names

String columnNames[] = { "Item Description", "Item Type", "Item Price" };

// Create some data

Object dataValues[][];

Item itm = new Item();

dataValues = itm.data;

// Create a new table instance

table = new JTable(dataValues, columnNames);

// //

JComboBox itemTypeCombobox = new JComboBox();

TableColumn column1 = table.getColumnModel().getColumn(1);

column1.setCellEditor(new DefaultCellEditor(itemTypeCombobox));

// //

// Add the table to a scrolling pane

scrollPane = new JScrollPane(table);

topPanel.add(scrollPane, BorderLayout.CENTER);

JButton button = new JButton("Add Item");

topPanel.add(button, BorderLayout.SOUTH);

}

public static void main(String[] args) {

Menu m = new Menu();

// Create an instance of the test application

Table mainFrame = new Table();

mainFrame.setVisible(true);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值