-1

次のコードがあります。

問題は、この部分で定義されている列ヘッダーではなく、表の個別の列に見出しを取得できないように見えることです

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); 

最初の列に全体が表示されます (したがって、表の唯一の列です)。したがって、データ フィールドには「名」のみが表示されます。

私の見出しのPrintlnは

[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);   



}
4

1 に答える 1

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"}
于 2015-03-18T21:47:19.187 に答える