2

I am trying to move a JTable object at the center of my JFrame by using the setBounds() method,but unfortunately it's not moving at the center. This is not possible neither by using the setbounds() method. Here is my code:

package table;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.*;
public class Table extends JFrame{
    JTable tabel;
Table()
{
   String[] columnNames = {"First Name","Last Name","Sport","# of Years","Vegetarian"};
    Object[][] data = {
    {"Kathy", "Smith",
     "Snowboarding", new Integer(5), new Boolean(false)},
    {"John", "Doe",
     "Rowing", new Integer(3), new Boolean(true)},
    {"Sue", "Black",
     "Knitting", new Integer(2), new Boolean(false)},
    {"Jane", "White",
     "Speed reading", new Integer(20), new Boolean(true)},
    {"Joe", "Brown",
     "Pool", new Integer(10), new Boolean(false)}
};
   tabel=new JTable(data,columnNames);
   tabel.setLayout(null);
   tabel.setBounds(100,900,700,400);
   tabel.setPreferredScrollableViewportSize(new Dimension(500,50));
   tabel.setFillsViewportHeight(true);
   JScrollPane pane=new JScrollPane(tabel);
  add(pane);
}
    public static void main(String[] args) {
        Table gui=new Table();
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setBounds(300,100,700,500);
        gui.setVisible(true);
    }    
}

what am i doing wrong?

Mr.s
  • 89
  • 6

0 Answers0