Example usage for javax.swing.event TableModelEvent getColumn

List of usage examples for javax.swing.event TableModelEvent getColumn

Introduction

In this page you can find the example usage for javax.swing.event TableModelEvent getColumn.

Prototype

public int getColumn() 

Source Link

Document

Returns the column for the event.

Usage

From source file:Main.java

public void tableChanged(TableModelEvent e) {
    int firstRow = e.getFirstRow();
    int lastRow = e.getLastRow();
    int index = e.getColumn();

    switch (e.getType()) {
    case TableModelEvent.INSERT:
        for (int i = firstRow; i <= lastRow; i++) {
            System.out.println(i);
        }// w w w. jav  a2  s. c om
        break;
    case TableModelEvent.UPDATE:
        if (firstRow == TableModelEvent.HEADER_ROW) {
            if (index == TableModelEvent.ALL_COLUMNS) {
                System.out.println("A column was added");
            } else {
                System.out.println(index + "in header changed");
            }
        } else {
            for (int i = firstRow; i <= lastRow; i++) {
                if (index == TableModelEvent.ALL_COLUMNS) {
                    System.out.println("All columns have changed");
                } else {
                    System.out.println(index);
                }
            }
        }
        break;
    case TableModelEvent.DELETE:
        for (int i = firstRow; i <= lastRow; i++) {
            System.out.println(i);
        }
        break;
    }
}

From source file:Main.java

Main() {
    JFrame jfrm = new JFrame("JTable Event Demo");
    jfrm.setSize(400, 200);//from  w ww. j a  v  a  2 s  .  c  o m
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    jtabOrders.setPreferredScrollableViewportSize(new Dimension(420, 62));

    ListSelectionModel rowSelMod = jtabOrders.getSelectionModel();

    ListSelectionModel colSelMod = jtabOrders.getColumnModel().getSelectionModel();

    rowSelMod.addListSelectionListener(this);
    colSelMod.addListSelectionListener(this);

    tm = jtabOrders.getModel();

    tm.addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent tme) {
            if (tme.getType() == TableModelEvent.UPDATE) {
                System.out.println("Cell " + tme.getFirstRow() + ", " + tme.getColumn() + " changed."
                        + " The new value: " + tm.getValueAt(tme.getFirstRow(), tme.getColumn()));
            }
        }
    });
    jfrm.add(new JScrollPane(jtabOrders));
    jfrm.setVisible(true);

}

From source file:gui.accessories.BattleSimFx.java

private BarChart createBarChart() {
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);//from  w w w .  j a va  2  s .  c o m
    yAxis.setLabel("Units Sold");

    final BarChart aChart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    tableModel.addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) aChart.getData()
                                .get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return aChart;
}

From source file:gui.accessories.GraphPopup.java

private BarChart createBarChartDynamic() {
    SampleTableModel tableModel = new SampleTableModel();
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);//from  www .  j ava 2  s . c  om
    yAxis.setLabel("Units Sold");

    final BarChart aChart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    aChart.setAnimated(true);
    tableModel.addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) aChart.getData()
                                .get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return aChart;
}

From source file:SampleTableModel.java

private BarChart createBarChart() {
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);//from   w w  w .j  av  a  2 s. c om
    yAxis.setLabel("Units Sold");

    final BarChart chart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    tableModel.addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) chart.getData()
                                .get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return chart;
}

From source file:MainFrame.MainFrame.java

public MainFrame() {
    //Create menu
    this.menuBar = new JMenuBar();
    this.menuProxy = new JMenu("Proxy");
    this.menuBar.add(menuProxy);
    this.cbMenuItem = new JCheckBoxMenuItem("? proxy");
    this.cbMenuItem.setMnemonic(KeyEvent.VK_C);

    ActionListener aListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            AbstractButton aButton = (AbstractButton) event.getSource();
            boolean selected = aButton.getModel().isSelected();
            if (selected) {
                SingleDataHolder.getInstance().isProxyActivated = true;
                SingleDataHolder.getInstance().proxyIpAdress = MainFrame.this.proxyIpAdress.getText();
                SingleDataHolder.getInstance().proxyPort = Integer.parseInt(MainFrame.this.proxyPort.getText());
                SingleDataHolder.getInstance().proxyLogin = MainFrame.this.proxyLogin.getText();
                SingleDataHolder.getInstance().proxyPassword = String
                        .valueOf(MainFrame.this.proxyPassword.getPassword());
            } else {
                SingleDataHolder.getInstance().isProxyActivated = false;
            }/*from  w  w w. java  2s .  c  o m*/
        }
    };
    this.cbMenuItem.addActionListener(aListener);

    this.proxyIpAdress = new JTextField();
    this.proxyPort = new JTextField();
    this.proxyLogin = new JTextField();
    ;
    this.proxyPassword = new JPasswordField();
    this.menuProxy.add(this.cbMenuItem);
    this.menuProxy.add(new JLabel("IP ?"));
    this.menuProxy.add(this.proxyIpAdress);
    this.menuProxy.add(new JLabel("? "));
    this.menuProxy.add(this.proxyPort);
    this.menuProxy.add(new JLabel(""));
    this.menuProxy.add(this.proxyLogin);
    this.menuProxy.add(new JLabel(""));
    this.menuProxy.add(this.proxyPassword);
    this.setJMenuBar(this.menuBar);

    communicator = new HttpCommunicator();
    myActionListener = new mainFrameActionListener();
    mainPanel = new JPanel(new BorderLayout());
    this.setContentPane(mainPanel);

    JPanel P = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 5));
    mainPanel.add(P, BorderLayout.NORTH);

    //Create Group label
    labelGroup = new JLabel("");
    P.add(labelGroup);
    //Create Group combo
    comboGroup = new JComboBox();
    comboGroup.addItem("?");
    comboGroup.addActionListener(myActionListener);
    P.add(comboGroup);

    //Create Date label
    labelDate = new JLabel("");
    P.add(labelDate);
    //Create Date combo
    comboDate = new JComboBox();
    comboDate.addItem("?");
    comboDate.addActionListener(myActionListener);
    P.add(comboDate);

    //Create Delete button
    buttonDelete = new JButton("");
    buttonDelete.setEnabled(false);
    buttonDelete.addActionListener(myActionListener);
    P.add(buttonDelete);

    //this.checkConnection = new CheckConnection(buttonDelete);

    buttonPasswordsManager = new JButton(" ");
    buttonPasswordsManager.addActionListener(myActionListener);
    P.add(buttonPasswordsManager);

    try {
        Image img = ImageIO.read(getClass().getResource("resources/table_refresh.png"));
        this.buttonRefresh = new JButton(new ImageIcon(img));
        this.buttonRefresh.addActionListener(myActionListener);
        this.buttonRefresh.setToolTipText(" ");
        P.add(buttonRefresh);
    } catch (IOException ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

    //CreateLessonTableModel
    lessonTableModel = new LessonTableModel();

    try {
        communicator.setCombos(comboGroup, comboDate, lessonTableModel);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, " ? ? .");
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

    //CreateTable
    table = new JTable(lessonTableModel);
    table.setFillsViewportHeight(true);
    table.setAutoCreateRowSorter(true);

    JScrollPane scrollP = new JScrollPane(table);
    mainPanel.add(scrollP, BorderLayout.CENTER);
    //Create Table sorter
    sorter = new TableRowSorter<LessonTableModel>(lessonTableModel);
    table.setRowSorter(sorter);
    table.getModel().addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            int row = e.getFirstRow();
            int column = e.getColumn();
            TableModel model = (TableModel) e.getSource();
            for (int i = 0; i < model.getRowCount(); i++) {
                if ((boolean) model.getValueAt(i, 2) == true) {
                    buttonDelete.setEnabled(true);
                    return;
                }
            }
            buttonDelete.setEnabled(false);
        }
    });

    //Standart block
    this.setSize(700, 400);
    this.setTitle(" ");
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent we) {
            System.exit(0);
        }
    });
    try {
        Image img = ImageIO.read(getClass().getResource("resources/appIcon.png"));
        this.setIconImage(img);
    } catch (IOException ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

    this.setVisible(true);
}

From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatMultiplePanel.java

/**
 * @param model//from w w w  .j  a v a2s.  co  m
 */
protected void addTableModelListener(DefaultTableModel model) {
    TableModelListener tml = new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            int row = e.getFirstRow();
            int column = e.getColumn();
            DefaultTableModel localModel = (DefaultTableModel) e.getSource();
            String columnName = localModel.getColumnName(column);

            if (columnName.equals(FIELD_VALUE_COL)) {
                int formatColumn = formatSwitchTbl.getColumnModel().getColumnIndex(DISPLAY_FORMAT_COL);
                DataObjDataFieldFormat format = (DataObjDataFieldFormat) localModel.getValueAt(row,
                        formatColumn);
                String value = (String) localModel.getValueAt(row, column);
                format.setValue(value);
                enableUIControls();
            }
        }
    };
    model.addTableModelListener(tml);
}

From source file:com.jskj.asset.client.panel.slgl.DiZhiYiHaoPinLingYongTuiKuJDialog.java

/**
 * Creates new form GuDingZiChanRuKu/*  w  ww . ja  va2s. com*/
 */
public DiZhiYiHaoPinLingYongTuiKuJDialog() {
    super();
    initComponents();

    zc = new ArrayList<ZiChanLieBiaotb>();
    userId = AssetClientApp.getSessionMap().getUsertb().getUserId();
    userName = AssetClientApp.getSessionMap().getUsertb().getUserName();
    department = AssetClientApp.getSessionMap().getDepartment().getDepartmentName();
    kucunmap = new HashMap();

    jTextFieldShenqingren.setText(userName);
    jTextFieldDept.setText(department);

    jTextField1.setText(DanHao.getDanHao("YHTK"));
    jTextField1.setEditable(false);

    jTextField2.setText(dateformate.format(new Date()).toString());
    jTextField2.setEditable(false);

    final BaseTable.SingleEditRowTable editTable = ((BaseTable) jTable1).createSingleEditModel(
            new String[][] { { "dzyhpId", "??" }, { "dzyhpName", "???", "true" },
                    { "dzyhpType", "?" }, { "dzyhpPinpai", "?", "false" },
                    { "dzyhpXinghao", "?" }, { "unitId", "??", "false" },
                    { "quantity", "?", "true" }, { "lylb.price", "", "false" },
                    { "total", "?" }, { "lylb.pihao", "??", "false" } });

    editTable.registerPopup(1, new IPopupBuilder() {
        @Override
        public int getType() {
            return IPopupBuilder.TYPE_POPUP_TABLE;
        }

        @Override
        public String getWebServiceURI() {
            return Constants.HTTP + Constants.APPID + "dizhiyihaopin/findtk";
        }

        @Override
        public String getConditionSQL() {
            int selectedColumn = jTable1.getSelectedColumn();
            int selectedRow = jTable1.getSelectedRow();
            Object newColumnObj = jTable1.getValueAt(selectedRow, selectedColumn);
            String sql = "";
            if (newColumnObj instanceof String && !newColumnObj.toString().trim().equals("")) {
                sql = "(dzyhp_name like \"%" + newColumnObj.toString() + "%\"" + " or zujima like \"%"
                        + newColumnObj.toString().toLowerCase() + "%\")";
            }
            return sql;
        }

        @Override
        public String[][] displayColumns() {
            return new String[][] { { "dzyhpId", "?ID" }, { "dzyhpName", "???" },
                    { "lylb.pihao", "??" } };
        }

        @Override
        public void setBindedMap(HashMap bindedMap) {
            if (bindedMap != null) {
                Object dzyhpId = bindedMap.get("dzyhpId");
                Object dzyhpName = bindedMap.get("dzyhpName");
                Object dzyhpType = bindedMap.get("dzyhpType");
                Object dzyhpPinpai = bindedMap.get("dzyhpPinpai");
                Object gdzcXinghao = bindedMap.get("dzyhpXinghao");
                //                    Object dzyhpValue = bindedMap.get("dzyhpValue");
                Object gdzcDanwei = bindedMap.get("unitId");

                editTable.insertValue(0, dzyhpId);
                editTable.insertValue(1, dzyhpName);
                editTable.insertValue(2, dzyhpType);
                editTable.insertValue(3, dzyhpPinpai);
                editTable.insertValue(4, gdzcXinghao);
                editTable.insertValue(5, gdzcDanwei);

                HashMap map = (HashMap) bindedMap.get("lylb");
                pihao = (String) map.get("pihao");
                saleprice = Float.parseFloat(map.get("price").toString());
                editTable.insertValue(7, saleprice);
                editTable.insertValue(9, pihao);
                Object lycount = bindedMap.get("count");

                //                    ZiChanLieBiaotb zclb = new ZiChanLieBiaotb();
                //                    zclb.setCgsqId(jTextField1.getText());
                //                    zclb.setCgzcId((Integer)dzyhpId);
                //                    zclb.setQuantity(0);
                //                    zc.add(zclb);

                //???
                kucunmap.put(dzyhpId + pihao, lycount);
            }

        }
    });

    jTable1.getModel().addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {

            int col = e.getColumn();
            int row = e.getFirstRow();

            if (col == 6 || col == 7) {
                if ((!(("" + jTable1.getValueAt(row, 6)).equals("")))
                        && (!(("" + jTable1.getValueAt(row, 7)).equals("")))) {
                    int count = Integer.parseInt("" + jTable1.getValueAt(row, 6));
                    float price = Float.parseFloat("" + jTable1.getValueAt(row, 7));
                    jTable1.setValueAt(price * count, row, 8);
                }
                int rows = jTable1.getRowCount();
                total = 0;
                for (int i = 0; i < rows; i++) {
                    if (!(("" + jTable1.getValueAt(i, 8)).equals(""))) {
                        total += Float.parseFloat("" + jTable1.getValueAt(i, 8));
                    }
                }
                totalprice.setText(total + "");
            }
        }

    });
}

From source file:table.TablePanel.java

public TablePanel(JPanel parent, GridBagConstraints c) {
    this.parent = parent;
    this.c = c;// ww w . j  a  v a 2  s  .com
    dataHandler = null;
    data = new ArrayList<>();
    selectedRows = new ArrayList<>();
    tableModel = new MyTableModel(data);
    table = new JTable(tableModel);
    table.getColumnModel().getColumn(0).setResizable(false);
    table.getColumnModel().getColumn(0).setMaxWidth(60);
    table.getColumnModel().getColumn(1).setResizable(false);
    table.getColumnModel().getColumn(1).setMaxWidth(50);
    table.getColumnModel().getColumn(2).setMaxWidth(90);
    table.getColumnModel().getColumn(49).setMaxWidth(60);
    for (int i = 0; i < tableModel.getColumnCount(); i++) {
        if (i > 14 && i < 31) {
            table.getColumnModel().getColumn(i).setMaxWidth(70);
        } else if (tableModel.columnNamesTemp[i].contains("LEVEL")) {
            if (tableModel.columnNamesTemp[i].equals("QEC LEVEL")) {
                table.getColumnModel().getColumn(i).setMinWidth(90);
                table.getColumnModel().getColumn(i).setMaxWidth(200);
            } else {
                table.getColumnModel().getColumn(i).setMaxWidth(90);
            }
            if (tableModel.columnNamesTemp[i - 1].equals("Work Pace")) {
                table.getColumnModel().getColumn(i - 1).setMinWidth(90);
                table.getColumnModel().getColumn(i - 1).setMaxWidth(150);
            } else {
                table.getColumnModel().getColumn(i - 1).setMaxWidth(90);
            }
        } else {
            // table.getColumnModel().getColumn(i).setMinWidth(120);
            // table.getColumnModel().getColumn(i).setMaxWidth(250);
        }
    }
    table.getColumnModel().getColumn(table.getColumnCount() - 1).setMaxWidth(60);
    table.getColumnModel().getColumn(table.getColumnCount() - 1).setResizable(false);

    table.setRowSelectionAllowed(true);
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.getModel().addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            if (!dataHandler.getDeleting() && (table.getSelectedRow() != -1)
                    && e.getColumn() != table.getColumnCount() - 1 && e.getColumn() != 1) {
                int row = table.getSelectedRow();
                int col = e.getColumn();

                if (col == 0 && (boolean) table.getValueAt(row, col) == true) {
                    if (!selectedRows.contains((Integer) row))
                        selectedRows.add(row);
                } else if (col == 0 && (boolean) table.getValueAt(row, col) == false) {
                    selectedRows.remove((Object) row);
                } else if (col != 0 && (boolean) table.getValueAt(row, table.getColumnCount() - 1)) {
                    dataHandler.dataEdited();
                }
            }
        }
    });

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        private int count = 0;

        @Override
        public void valueChanged(ListSelectionEvent arg0) {
            if (count > 1 && !arg0.getValueIsAdjusting()) {
                int[] draggedRows = table.getSelectedRows();
                for (int i = 0; i < draggedRows.length; i++)
                    if (selectedRows.contains((Integer) draggedRows[i])) {
                        selectedRows.remove((Integer) draggedRows[i]);
                        table.setValueAt(false, draggedRows[i], 0);
                    } else {
                        selectedRows.add((Integer) draggedRows[i]);
                        table.setValueAt(true, draggedRows[i], 0);
                    }
                // Finalize
                count = 0;
            } else if (arg0.getValueIsAdjusting())
                count++;
            else
                count = 0;
        }
    });

    // {
    //
    // @Override
    // public Component prepareRenderer(TableCellRenderer renderer,
    // int row, int column) {
    // JLabel label = (JLabel) super.prepareRenderer(renderer, row, column);
    // if ((boolean) table.getValueAt(row, table.getColumnCount() - 1) ==
    // false) {
    // if ((int) row % 2 == 0) {
    // label.setBackground(new Color(244, 226,215));
    // } else {
    // label.setBackground(new Color(241, 220,205));
    // }
    // } else {
    // if ((int) row% 2 == 0) {
    // label.setBackground(new Color(255, 255, 255));
    // } else {
    // label.setBackground(new Color(252, 252, 252));
    // }
    //
    // }
    // if(table.getSelectedRow()==row)
    // label.setBackground(Color.LIGHT_GRAY);
    // return label;
    // }
    // };
    // table.prepareRenderer(null, WIDTH, WIDTH);
    // table.setRowSelectionAllowed(true);
    // table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setDefaultRenderer(Object.class, new MyTableCellRenderer());

    // {
    //
    // @Override
    // public Component getTableCellRendererComponent(JTable table, Object
    // value, boolean isSelected, boolean hasFocus, int row, int column) {
    // JLabel label = (JLabel) table.prepareRenderer(null, row, column);
    // if ((boolean) table.getValueAt(row, table.getColumnCount() - 1) ==
    // false) {
    // if ((int) row % 2 == 0) {
    // label.setBackground(new Color(244, 226,215));
    // } else {
    // label.setBackground(new Color(241, 220,205));
    // }
    // } else {
    // if ((int) row% 2 == 0) {
    // label.setBackground(new Color(255, 255, 255));
    // } else {
    // label.setBackground(new Color(252, 252, 252));
    // }
    //
    // }
    // if(table.getSelectedRow()==row)
    // label.setBackground(Color.LIGHT_GRAY);
    // return label;
    // }
    // });
    // {
    //
    // @Override
    // public Component getTableCellRendererComponent(JTable table, Object
    // value, boolean isSelected, boolean hasFocus, int row, int column) {
    // Component cell= table.getCellRenderer(row,
    // column).getTableCellRendererComponent(table, value, isSelected,
    // hasFocus, row, column);
    //
    //
    // for(int i=1;i<table.getRowCount();i++) {
    // if((boolean)table.getValueAt(i, table.getColumnCount()-1) ==false)
    // {
    // setForeground(Color.black);
    // setBackground(Color.red);
    // }
    // else
    // {
    // setBackground(Color.white);
    // setForeground(Color.black);
    // }
    // }
    // return cell;
    // }
    // });
    // DefaultTableCellRenderer rightRenderer = new
    // DefaultTableCellRenderer();
    // rightRenderer.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT);
    for (int i = 0; i < tableModel.getColumnCount(); i++) {
        table.getTableHeader().getColumnModel().getColumn(i)
                .setHeaderRenderer(new HeaderRenderer(table, alignments[1]));
        // table.getColumnModel().getColumn(i).setCellRenderer(new
        // MyTableCellRenderer());
    }
    table.getTableHeader().setReorderingAllowed(false);
    table.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    table.setRowHeight(25);
    // table.setPreferredScrollableViewportSize(new Dimension(10000, 200));

    // Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    //      JViewport tableView = new JViewport();
    //      tableView.add(table);
    //      scrollPane.setViewport(tableView);
    parent.setSize(table.getWidth(), table.getHeight());
    //      parent.setPreferredSize(new Dimension(70000,10000));
    //      scrollPane.setVerticalScrollBar(new JScrollBar(JScrollBar.VERTICAL));
    //      scrollPane.setHorizontalScrollBar(new JScrollBar(JScrollBar.HORIZONTAL));
    // Add the scroll pane to this panel.
    //      parent.add(table.getTableHeader());
    //      parent.add(table, c);
    // Add header in NORTH slot
    parent.add(table.getTableHeader(), BorderLayout.NORTH);

    // Add table itself to CENTER slot
    parent.add(table, BorderLayout.CENTER);
}

From source file:dbseer.gui.user.DBSeerDataSet.java

@Override
public void tableChanged(TableModelEvent tableModelEvent) {
    if (tableModelEvent.getFirstRow() == DBSeerDataSet.TYPE_USE_ENTIRE_DATASET
            && tableModelEvent.getColumn() == 1) {
        if (((Boolean) table.getValueAt(DBSeerDataSet.TYPE_USE_ENTIRE_DATASET, 1)).booleanValue() == true) {
            tableModel.setUseEntireDataSet(true);
        } else {/*from   w w w.  j a  v a2  s.c  o m*/
            tableModel.setUseEntireDataSet(false);
        }
    }
    //      if (tableModelEvent.getFirstRow() == DBSeerDataSet.TYPE_NUM_TRANSACTION_TYPE &&
    //            tableModelEvent.getColumn() == 1)
    //      {
    //         int numTransactionType = (Integer.parseInt((String)table.getValueAt(DBSeerDataSet.TYPE_NUM_TRANSACTION_TYPE, 1)));
    //         int currentRowCount = tableModel.getRowCount();
    //
    //         ArrayList<String> previousTypeNames = new ArrayList<String>();
    //         for (int i = DBSeerDataSet.TYPE_NUM_TRANSACTION_TYPE + 1; i < DBSeerDataSet.TYPE_NUM_TRANSACTION_TYPE + 1 + numTransactionTypes; ++i) //tableModel.getRowCount(); ++i)
    //         {
    //            previousTypeNames.add((String)table.getValueAt(i, 1));
    //         }
    //
    ////         for (int i = currentRowCount-1; i > DBSeerDataSet.TYPE_NUM_TRANSACTION_TYPE; --i)
    //         for (int i = DBSeerDataSet.TYPE_NUM_TRANSACTION_TYPE + numTransactionTypes; i > DBSeerDataSet.TYPE_NUM_TRANSACTION_TYPE; --i)
    //         {
    //            tableModel.removeRow(i);
    //         }
    //
    //         for (int i = 0; i < numTransactionType; ++i)
    //         {
    //            String name = (i < previousTypeNames.size()) ? previousTypeNames.get(i) : "Type " + (i+1);
    //            tableModel.addRow(new Object[]{"Name of Transaction Type " + (i+1), name});
    //         }
    //      }
}