In this course design, most of the content is designed to be very smooth, did not encounter too much problem, but in the panel to join JTable did spend a part of the time, here to summarize the solution:
To define a control:
New JPanel (); JTable tablenew JScrollPane ();
Define the two parameters in the JTable:
New object[]{"Bus number", "Passenger capacity", "origin", "destination", "Departure Time", "Arrival Time", "Time required"}; // Column Name New OBJECT[50][7]; // number of rows, number of columns
Put the jtable on the JPanel, must have jscrollpane over, in order to ensure that the column name normal display:
New JTable (Rowdata,columnnames), Jscrollpane.setbounds (550, 650); Jscrollpane.setviewportview ( table); // that's important . Table.setrowheight (/** * Word Center display setting */new Defaulttablecellrenderer ();
R.sethorizontalalignment (jlabel.center); Table.setdefaultrenderer (Object. class , R); add (JScrollPane);
Effect:
Java Graphical Interface (GUI)--How to successfully put JTable into the panel