1 / 9

JTable

JTable. Prepared by Petar Agov. Jtable – The Basics. Jtable is a GUI element in Java, extending the JPane class . It’s basic purpose is to present data into a table, much like Microsoft Excel Jtable does not store or cache the data, it simply displays it.

quiana
Download Presentation

JTable

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JTable Prepared by PetarAgov

  2. Jtable – The Basics • Jtable is a GUI element in Java, extending the JPane class. • It’s basic purpose is to present data into a table, much like Microsoft Excel • Jtable does not store or cache the data, it simply displays it. • By default, the user can edit the data.(e.g. change entries, move columns around)

  3. Jtable View

  4. How to do it? public Table(){ setLayout(new FlowLayout()); String[] colNames = {"First Name", "Last Name", "ID#", "Standing"}; Object[][] dataset ={ {"Petar", "Agov", "100079581", "Junior"}, {"Pavel", "Agov", "100096587", "Junior"}, {"Elzem", "Emin", "100052369", "Sophomore"}, {"Ivan", "Ivanov", "100075834", "Senior"}, {"Victor","Jubirca", "100029854", "Freshman"}, };

  5. How to do it? (Cont.) table = new JTable(dataset, colNames); - create an instance of the table table.setPreferredScrollableViewportSize(new Dimension(300,50)); table.setFillsViewportHeight(true); JScrollPanescrollPane = new JScrollPane(table); add(scrollPane); }

  6. How to do it? (Cont.) public static void main(String args[]){ Table MyTable = new Table(); MyTable.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MyTable.setSize(400,400); MyTable.setVisible(true); }

  7. Special Mentions • The FlowLayout class puts components in a row, sized at their preferred size. • The JScrollPane constructor is invoked with an argument that refers to the table object. This creates a scroll pane as a container for the table; the table is automatically added to the container. • JTable.setFillsViewportHeight is invoked to set the fillsViewportHeight property. When this property is true the table uses the entire height of the container, even if the table doesn't have enough rows to use the whole vertical space. This makes it easier to use the table as a drag-and-drop target.

  8. Special Mentions (cont.) • The scroll pane automatically places the table header at the top of the viewport. The column names remain visible at the top of the viewing area when the table data is scrolled. • If you are using a table without a scroll pane, then you must get the table header component and place it yourself. • setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) – ends the project when the table is closed.

  9. THANK YOU FOR YOUR ATTENTION!

More Related