我有以下代码:
问题似乎无法将标题放入表格中的单独列,而是我在此部分中定义的列标题
String[] columnNames ={container.toString()};
并且源自
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
//create array--------------
ArrayList list = new ArrayList();
Scanner scanner = new Scanner(in);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
//add line to array-------------
list.add(line);
}
//get headings of data------------------
//String heading[] = list.get(2).toString();
String[] simpleArray = new String[list.size()];
list.toArray(simpleArray);
String j = (String) list.get(2);
String [] items = j.split(";");
List<String> container = Arrays.asList(items);
createUserInterface(container);
在第一列中完整显示(因此表中唯一的列) 因此,我只看到&#34;名字&#34;出现在数据字段
中我的标题打印
[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R,S] *I have substituted my actual headings with letters
帮助表示赞赏
以下代码 -
public void createUserInterface(List<String>container) {
//create user interface---------------------
setLayout( new BorderLayout());
setTitle("Fund");//setTitle is also a JAVA Parameter
setSize(2000, 200);
setBackground(Color.gray);
setDefaultCloseOperation(EXIT_ON_CLOSE);
// Create a panel to hold all other components
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add(topPanel);
//
System.out.println(container.toString());
List list = Arrays.asList(container);
Object[] columnNames ={list};
Object[][] data = {{"First Name", "Last Name", "Sport", "# of Years","First Name", "Last Name", "Sport", "# of Years","First Name", "Last Name", "Sport", "# of Years","First Name", "Last Name", "Sport", "# of Years","First Name", "Last Name", "Sport", "# of Years"}};
table = new JTable(data, columnNames);
// Create a new table instance
scrollPane = new JScrollPane( table );
topPanel.add( scrollPane, BorderLayout.CENTER );
setVisible(true);
}
答案 0 :(得分:2)
您希望这会回归:container.toString()
?怎么可能代表你的桌面标题?
如果您希望A到S的字母成为您的JTable列标题(我猜测您正在尝试做的事情),为什么不简单地使用此数组?
String[] columnNames = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", "N", "O", "P", "Q", "R", "S"}