Java graphical Interface (GUI)--How to successfully put JTable into the panel

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.