prepared by petar agov jtable. jtable – the basics jtable is a gui element in java, extending the...

9
PREPARED BY PETAR AGOV JTABLE

Upload: clare-bruce

Post on 18-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: PREPARED BY PETAR AGOV JTABLE. JTABLE – THE BASICS Jtable is a GUI element in Java, extending the JPane class. It’s basic purpose is to present data into

P R E PA R E D BY P E TA R AG OV

JTABLE

Page 2: PREPARED BY PETAR AGOV JTABLE. JTABLE – THE BASICS Jtable is a GUI element in Java, extending the JPane class. It’s basic purpose is to present data into

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)

Page 3: PREPARED BY PETAR AGOV JTABLE. JTABLE – THE BASICS Jtable is a GUI element in Java, extending the JPane class. It’s basic purpose is to present data into

JTABLE VIEW

Page 4: PREPARED BY PETAR AGOV JTABLE. JTABLE – THE BASICS Jtable is a GUI element in Java, extending the JPane class. It’s basic purpose is to present data into

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"}, };

Page 5: PREPARED BY PETAR AGOV JTABLE. JTABLE – THE BASICS Jtable is a GUI element in Java, extending the JPane class. It’s basic purpose is to present data into

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); JScrollPane scrollPane = new JScrollPane(table); add(scrollPane); }

Page 6: PREPARED BY PETAR AGOV JTABLE. JTABLE – THE BASICS Jtable is a GUI element in Java, extending the JPane class. It’s basic purpose is to present data into

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

Page 7: PREPARED BY PETAR AGOV JTABLE. JTABLE – THE BASICS Jtable is a GUI element in Java, extending the JPane class. It’s basic purpose is to present data into

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.

Page 8: PREPARED BY PETAR AGOV JTABLE. JTABLE – THE BASICS Jtable is a GUI element in Java, extending the JPane class. It’s basic purpose is to present data into

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.

Page 9: PREPARED BY PETAR AGOV JTABLE. JTABLE – THE BASICS Jtable is a GUI element in Java, extending the JPane class. It’s basic purpose is to present data into

THANK YOU FOR YOUR ATTENTION!