Example usage for javax.swing.table TableColumn setHeaderValue

List of usage examples for javax.swing.table TableColumn setHeaderValue

Introduction

In this page you can find the example usage for javax.swing.table TableColumn setHeaderValue.

Prototype

@BeanProperty(description = "The text to be used by the header renderer.")
public void setHeaderValue(Object headerValue) 

Source Link

Document

Sets the Object whose string representation will be used as the value for the headerRenderer.

Usage

From source file:Main.java

public static void main(String args[]) {
    Object rows[][] = { { "one", "ichi" }, { "two", "ni" }, { "three", "san" }, { "four", "shi" },
            { "five", "go" }, { "six", "roku" }, { "seven", "shichi" }, { "eight", "hachi" }, { "nine", "kyu" },
            { "ten", "ju" } };
    Object headers[] = { "English", "Japanese" };
    String title = (args.length == 0 ? "JTable Sample" : args[0]);
    JFrame frame = new JFrame(title);

    TableColumnModel columnModel = new DefaultTableColumnModel();
    TableColumn firstColumn = new TableColumn(1);
    firstColumn.setHeaderValue(headers[1]);
    columnModel.addColumn(firstColumn);/*from w  ww . j av  a 2  s .  c o m*/
    TableColumn secondColumn = new TableColumn(0);
    secondColumn.setHeaderValue(headers[0]);
    columnModel.addColumn(secondColumn);
    ListSelectionModel selectionModel = new DefaultListSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //    JTable table = new JTable(model, columnModel, selectionModel);
    JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:TableColumnTester.java

public static void main(String args[]) {
    Object rows[][] = { { "one", "ichi" }, { "two", "ni" }, { "three", "san" }, { "four", "shi" },
            { "five", "go" }, { "six", "roku" }, { "seven", "shichi" }, { "eight", "hachi" }, { "nine", "kyu" },
            { "ten", "ju" } };
    Object headers[] = { "English", "Japanese" };
    String title = (args.length == 0 ? "JTable Sample" : args[0]);
    JFrame frame = new JFrame(title);
    TableModel model = new DefaultTableModel(rows, headers);
    TableColumnModel columnModel = new DefaultTableColumnModel();
    TableColumn firstColumn = new TableColumn(1);
    firstColumn.setHeaderValue(headers[1]);
    columnModel.addColumn(firstColumn);/*from w  ww.j a v  a  2s.com*/
    TableColumn secondColumn = new TableColumn(0);
    secondColumn.setHeaderValue(headers[0]);
    columnModel.addColumn(secondColumn);
    ListSelectionModel selectionModel = new DefaultListSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //    JTable table = new JTable(model, columnModel, selectionModel);
    JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    String rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } };
    String headers[] = { "Upper", "Lower" };

    JFrame frame = new JFrame("Label Header");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);

    Border headerBorder = UIManager.getBorder("TableHeader.cellBorder");

    JLabel headerLabel1 = new JLabel(headers[0], JLabel.CENTER);
    headerLabel1.setBorder(headerBorder);
    JLabel headerLabel2 = new JLabel(headers[1], JLabel.CENTER);
    headerLabel2.setBorder(headerBorder);

    TableCellRenderer renderer = new JComponentTableCellRenderer();

    TableColumnModel columnModel = table.getColumnModel();

    TableColumn column0 = columnModel.getColumn(0);
    TableColumn column1 = columnModel.getColumn(1);

    column0.setHeaderRenderer(renderer);
    column0.setHeaderValue(headerLabel1);

    column1.setHeaderRenderer(renderer);
    column1.setHeaderValue(headerLabel2);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);/*www . jav a  2  s  .co  m*/
    frame.setVisible(true);
}

From source file:JComponentTableCellRenderer.java

public static void main(String args[]) {
    final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } };
    JFrame frame = new JFrame("Label Header");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String headers[] = { "English", "#" };
    JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);

    Icon redIcon = new ImageIcon("yourFile.gif");
    Icon blueIcon = new ImageIcon("yourFile.gif");

    Border headerBorder = UIManager.getBorder("TableHeader.cellBorder");

    JLabel blueLabel = new JLabel(headers[0], blueIcon, JLabel.CENTER);
    blueLabel.setBorder(headerBorder);/*  ww w  .  j  av  a  2  s  .  c  om*/
    JLabel redLabel = new JLabel(headers[1], redIcon, JLabel.CENTER);
    redLabel.setBorder(headerBorder);

    TableCellRenderer renderer = new JComponentTableCellRenderer();

    TableColumnModel columnModel = table.getColumnModel();

    TableColumn column0 = columnModel.getColumn(0);
    TableColumn column1 = columnModel.getColumn(1);

    column0.setHeaderRenderer(renderer);
    column0.setHeaderValue(blueLabel);

    column1.setHeaderRenderer(renderer);
    column1.setHeaderValue(redLabel);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);

    model = (DefaultTableModel) table.getModel();
    TableColumn col = new TableColumn(model.getColumnCount());

    // Ensure that auto-create is off
    if (table.getAutoCreateColumnsFromModel()) {
        throw new IllegalStateException();
    }//ww  w  . j ava 2s.co  m
    col.setHeaderValue("Col3");
    table.addColumn(col);
    model.addColumn("Col3", new Object[] { "v3" });

}

From source file:LabelHeaderSample.java

public static void main(String args[]) {
    Object rows[][] = { { "one", "ichi - \u4E00" }, { "two", "ni - \u4E8C" }, { "three", "san - \u4E09" },
            { "four", "shi - \u56DB" }, { "five", "go - \u4E94" }, { "six", "roku - \u516D" },
            { "seven", "shichi - \u4E03" }, { "eight", "hachi - \u516B" }, { "nine", "kyu - \u4E5D" },
            { "ten", "ju - \u5341" } };
    JFrame frame = new JFrame("Label Header");
    String headers[] = { "English", "Japanese" };
    JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);

    Icon redIcon = new DiamondIcon(Color.red);
    Icon blueIcon = new DiamondIcon(Color.blue);

    Border headerBorder = UIManager.getBorder("TableHeader.cellBorder");

    JLabel blueLabel = new JLabel(headers[0], blueIcon, JLabel.CENTER);
    blueLabel.setBorder(headerBorder);/*w w  w .j av  a2 s  .c  o  m*/
    JLabel redLabel = new JLabel(headers[1], redIcon, JLabel.CENTER);
    redLabel.setBorder(headerBorder);

    TableCellRenderer renderer = new JComponentTableCellRenderer();

    TableColumnModel columnModel = table.getColumnModel();

    TableColumn column0 = columnModel.getColumn(0);
    TableColumn column1 = columnModel.getColumn(1);

    column0.setHeaderRenderer(renderer);
    column0.setHeaderValue(blueLabel);

    column1.setHeaderRenderer(renderer);
    column1.setHeaderValue(redLabel);

    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:net.kamhon.ieagle.swing.table.KTable.java

private void initComponents(List<KTableColumn> columns) {
    tableModel = new KTableModel<T>(this, columns);
    setModel(tableModel);/*from w w w  . j  a v a2  s  .c  o  m*/

    // final KTable<T> table = this;

    for (int i = 0; i < columns.size(); i++) {
        KTableColumn column = columns.get(i);
        TableColumn tc = columnModel.getColumn(i);
        tc.setHeaderValue(column.getColumnLabel());

        if (column instanceof KTableCheckBoxColumn) {
            BooleanEditor cellEditor = new BooleanEditor();

            if (column instanceof KTableRowCheckBoxColumn) {
                /*final JCheckBox component = (JCheckBox) cellEditor.getComponent();
                component.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e) {
                  int[] selectedRows = table.getSelectedRows();
                  int selectedRow = table.getSelectedRow();
                          
                  log.debug("selectedRows = " + selectedRows);
                  log.debug("selectedRow = " + selectedRow);
                  if (component.isSelected()) {
                        
                  }
                   }
                });*/
                // log.debug("component = " + component);
            }

            tc.setCellEditor(cellEditor);
            tc.setCellRenderer(this.getDefaultRenderer(Boolean.class));
            tc.setHeaderRenderer(new KTableHeaderCheckBox(this));
        } else if (column instanceof KTableTextColumn) {
            KTextField textField = new KTextField();
            textField.setEditable(false);

            tc.setCellEditor(new GenericEditor(textField));
        }
    }

    setColumnControlVisible(true);
    setShowGrid(false, false);
}

From source file:DisplayModeModel.java

private void initComponents(Container c) {
    setContentPane(c);/*w ww .ja  va  2 s.  c  om*/
    c.setLayout(new BorderLayout());
    // Current DM
    JPanel currentPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    c.add(currentPanel, BorderLayout.NORTH);
    JLabel current = new JLabel("Current Display Mode : ");
    currentPanel.add(current);
    currentPanel.add(currentDM);
    // Display Modes
    JPanel modesPanel = new JPanel(new GridLayout(1, 2));
    c.add(modesPanel, BorderLayout.CENTER);
    // List of display modes
    for (int i = 0; i < COLUMN_WIDTHS.length; i++) {
        TableColumn col = new TableColumn(i, COLUMN_WIDTHS[i]);
        col.setIdentifier(COLUMN_NAMES[i]);
        col.setHeaderValue(COLUMN_NAMES[i]);
        dmList.addColumn(col);
    }
    dmList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    dmList.getSelectionModel().addListSelectionListener(this);
    modesPanel.add(dmPane);
    // Controls
    JPanel controlsPanelA = new JPanel(new BorderLayout());
    modesPanel.add(controlsPanelA);
    JPanel controlsPanelB = new JPanel(new GridLayout(2, 1));
    controlsPanelA.add(controlsPanelB, BorderLayout.NORTH);
    // Exit
    JPanel exitPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    controlsPanelB.add(exitPanel);
    exitPanel.add(exit);
    // Change DM
    JPanel changeDMPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    controlsPanelB.add(changeDMPanel);
    changeDMPanel.add(changeDM);
    controlsPanelA.add(new JPanel(), BorderLayout.CENTER);
}

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);/*from  w  w  w. ja  va2s.co  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:finalproject.BloodGlucoseGUI.java

/**
 * Constructor//from w w  w .ja v a2  s .  c  om
 * Creates new form BloodGlucoseGUI
 */
// I would put most of it in initComponents if I could 
// edit that generated code.
public BloodGlucoseGUI() {
    initComponents();
    //jfc = new JFileChooser("Resources/Data");

    // For "commercial" use
    //jfc = new JFileChooser("C:\\Program Files\\BGDataAnalysis\\Data");
    jfc = new JFileChooser("C:\\BGDataAnalysis\\Data");

    tabMod = new MyTableModel();
    jTable2.setModel(tabMod);

    listMod = new DefaultListModel();
    jList1.setModel(listMod);

    JTableHeader th = jTable2.getTableHeader();
    TableColumnModel tcm = th.getColumnModel();
    TableColumn tc = tcm.getColumn(0);
    tc.setHeaderValue("Time");
    tc = tcm.getColumn(1);
    tc.setHeaderValue("Blood Glucose");
    th.repaint();

    notesTextArea.setLineWrap(true);
    notesTextArea.setWrapStyleWord(true);

    notesTextArea.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                e.consume();

                ErrorGUIs.Popup pu = new ErrorGUIs.Popup();
                pu.add("Please don't press the ENTER button!");
                pu.display();
            }
        }
    });
}