Example usage for javax.swing.table TableColumnModel getColumn

List of usage examples for javax.swing.table TableColumnModel getColumn

Introduction

In this page you can find the example usage for javax.swing.table TableColumnModel getColumn.

Prototype

public TableColumn getColumn(int columnIndex);

Source Link

Document

Returns the TableColumn object for the column at columnIndex.

Usage

From source file:org.jfree.chart.demo.selection.SelectionDemo8.java

/**
 * A demonstration application showing how to create a simple time series
 * chart. This example uses monthly data.
 *
 * @param title  the frame title./*from   ww w .j a  va  2 s .c o m*/
 */
public SelectionDemo8(String title) {
    super(title);
    ChartPanel chartPanel = (ChartPanel) createDemoPanel();
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setRangeZoomable(false);

    JFreeChart chart = chartPanel.getChart();
    XYPlot plot = (XYPlot) chart.getPlot();
    this.dataset = (TimeSeriesCollection) plot.getDataset();
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.add(chartPanel);

    this.model = new DefaultTableModel(new String[] { "Series:", "Item:", "Period:", "Value:" }, 0);
    this.table = new JTable(this.model);
    TableColumnModel tcm = this.table.getColumnModel();
    tcm.getColumn(3).setCellRenderer(new NumberCellRenderer());
    JPanel p = new JPanel(new BorderLayout());
    JScrollPane scroller = new JScrollPane(this.table);
    p.add(scroller);
    p.setBorder(BorderFactory.createCompoundBorder(new TitledBorder("Selected Items: "),
            new EmptyBorder(4, 4, 4, 4)));
    split.add(p);
    setContentPane(split);

}

From source file:org.jfree.chart.demo.selection.SelectionDemo1.java

/**
 * A demonstration application showing how to create a simple time series
 * chart. This example uses monthly data.
 * //from w  ww . j  a va  2  s  . c o m
 * @param title  the frame title.
 */
public SelectionDemo1(String title) {
    super(title);
    ChartPanel chartPanel = (ChartPanel) createDemoPanel();
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    JFreeChart chart = chartPanel.getChart();
    XYPlot plot = (XYPlot) chart.getPlot();
    this.dataset = (TimeSeriesCollection) plot.getDataset();
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.add(chartPanel);

    this.model = new DefaultTableModel(new String[] { "Series:", "Item:", "Period:", "Value:" }, 0);
    this.table = new JTable(this.model);
    TableColumnModel tcm = this.table.getColumnModel();
    tcm.getColumn(3).setCellRenderer(new NumberCellRenderer());
    JPanel p = new JPanel(new BorderLayout());
    JScrollPane scroller = new JScrollPane(this.table);
    p.add(scroller);
    p.setBorder(BorderFactory.createCompoundBorder(new TitledBorder("Selected Items: "),
            new EmptyBorder(4, 4, 4, 4)));
    split.add(p);
    setContentPane(split);

}

From source file:FrozenColumnHeader.java

public void addNotify() {
    TableColumn column;/*  www  .  j a v a 2s .  co  m*/
    super.addNotify();
    TableColumnModel mainModel = mainTable.getColumnModel();
    TableColumnModel headerModel = new DefaultTableColumnModel();
    int frozenWidth = 0;
    for (int i = 0; i < columnCount; i++) {
        column = mainModel.getColumn(0);
        mainModel.removeColumn(column);
        headerModel.addColumn(column);
        frozenWidth += column.getPreferredWidth() + headerModel.getColumnMargin();
    }
    headerTable.setColumnModel(headerModel);
    Component columnHeader = getColumnHeader().getView();
    getColumnHeader().setView(null);
    JScrollPane mainScrollPane = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, mainTable);
    mainScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, new JLabel("..."));

    headerTable.setPreferredScrollableViewportSize(new Dimension(frozenWidth, 0));
}

From source file:TableCellRenderTest.java

public TableCellRenderFrame() {
    setTitle("TableCellRenderTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    TableModel model = new PlanetTableModel();
    JTable table = new JTable(model);
    table.setRowSelectionAllowed(false);

    // set up renderers and editors

    table.setDefaultRenderer(Color.class, new ColorTableCellRenderer());
    table.setDefaultEditor(Color.class, new ColorTableCellEditor());

    JComboBox moonCombo = new JComboBox();
    for (int i = 0; i <= 20; i++)
        moonCombo.addItem(i);//ww w. j av a2  s. c  o m

    TableColumnModel columnModel = table.getColumnModel();
    TableColumn moonColumn = columnModel.getColumn(PlanetTableModel.MOONS_COLUMN);
    moonColumn.setCellEditor(new DefaultCellEditor(moonCombo));
    moonColumn.setHeaderRenderer(table.getDefaultRenderer(ImageIcon.class));
    moonColumn.setHeaderValue(new ImageIcon("Moons.gif"));

    // show table

    table.setRowHeight(100);
    add(new JScrollPane(table), BorderLayout.CENTER);
}

From source file:ru.codemine.pos.ui.windows.document.startbalances.StartBalanceWindow.java

@Override
public void showWindow(StartBalance startBalance) {
    if (!actionListenersInit)
        setupActionListeners();/* www  . j  a v  a  2 s  . c o  m*/

    this.startBalance = startBalance;

    List<Store> stores = storeService.getAll();

    idField.setText(startBalance.getId() == null ? "" : startBalance.getId().toString());
    creationTimeField.setDate(startBalance.getCreationTime().toDate());
    documentTimeField.setDate(startBalance.getDocumentTime().toDate());
    creatorField.setText(startBalance.getCreator() == null ? application.getActiveUser().getUsername()
            : startBalance.getCreator().getUsername());

    storeFieldComboBox.removeAllItems();
    for (Store s : stores) {
        storeFieldComboBox.addItem(s.getName());
    }

    tableModel = new StartBalanceContentTableModel(startBalance);
    contentTable.setModel(tableModel);
    TableColumnModel columnModel = contentTable.getColumnModel();
    columnModel.getColumn(0).setMaxWidth(10);
    contentTable.setEditable(true);

    setVisible(true);
}

From source file:ru.codemine.pos.ui.windows.products.ProductWindow.java

@Override
public void showWindow(Product product) {
    if (!actionListenersInit)
        setupActionListeners();//w  ww  .  j ava  2 s .  c  om

    this.product = product;

    setTitle(" - " + product.getName());

    idField.setText(product.getId() == null ? "" : product.getId().toString());
    artikulField.setText(product.getArtikul());
    nameField.setText(product.getName());
    barcodeField.setText(product.getBarcode());
    priceField.setValue(product.getPrice());

    if (product.getId() == null) {
        artikulField.setEditable(true);
    } else {
        artikulField.setEditable(false);
    }

    List<Store> proxedStores = storeService.getAll();
    List<Store> stores = new ArrayList<>();
    for (Store s : proxedStores) {
        stores.add(storeService.unproxyStocks(s));
    }
    stocksTable.setModel(new ProductByStoresTableModel(product, stores));

    TableColumnModel columnModel = stocksTable.getColumnModel();
    columnModel.getColumn(0).setMaxWidth(10);

    File imgFile = new File("images/products/" + product.getArtikul() + ".jpg");
    String imgPath = "images/products/default.jpg";

    if (imgFile.exists() && !imgFile.isDirectory()) {
        imgPath = imgFile.getAbsolutePath();
    }

    ImageIcon ico = new ImageIcon(imgPath);
    if (ico.getIconHeight() > 0) {
        Image img = ico.getImage().getScaledInstance(200, 200, Image.SCALE_SMOOTH);
        imagePanel.setImage(img, true);
    }

    setVisible(true);
}

From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo7.java

public void setXLabel(String xLabel) {

    domainLabel = xLabel;/*w  w w  .j  a  v  a2 s  .  c  o m*/
    TableColumnModel columnModel = dataTable.getColumnModel();
    columnModel.getColumn(0).setHeaderValue(xLabel);
    dataTable.setTableHeader(new EditableHeader(columnModel));
}

From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo7.java

public void setYLabel(String yLabel) {
    rangeLabel = yLabel;/*  w  ww  .  j av a  2  s  .co  m*/
    TableColumnModel columnModel = dataTable.getColumnModel();
    columnModel.getColumn(1).setHeaderValue(yLabel);
    //   System.out.println("histogram7 setting yLabel="+yLabel);
    dataTable.setTableHeader(new EditableHeader(columnModel));
}

From source file:com.sec.ose.osi.ui.frm.main.manage.AddProjectTableModel.java

public void setColumnWidth(JTable table) {
    TableColumnModel cm = table.getColumnModel();

    for (int i = 0; i < columnWidth.length; i++) {
        cm.getColumn(i).setPreferredWidth(columnWidth[i]);
    }/*from w w  w  .  j a  va  2 s.  co m*/
}

From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo5.java

public void setYLabel(String yLabel) {
    rangeLabel = yLabel;//from w w w .jav  a  2  s.  c  om
    TableColumnModel columnModel = dataTable.getColumnModel();
    columnModel.getColumn(0).setHeaderValue(yLabel);
    dataTable.setTableHeader(new EditableHeader(columnModel));
}