Table Cell Editor: ComboBoxCellEditor : Table Renderer Editor « Swing JFC « Java






Table Cell Editor: ComboBoxCellEditor

  
/*
Applied Java Patterns

Stephen Stelting, Olav Maassen
Paper, 598 pp.
ISBN: 0130935387
Published: DEC 26, 2001    
*/

import java.awt.Container;
import java.awt.Dimension;
import javax.swing.*;

public class TableDemoApplet extends JApplet {
    
    public TableDemoApplet() {
        createGUI(getContentPane());
    }
    
    private static void createGUI(Container contentPane) {
        Object[][] rowData = new String[][] { {"98-43", "AraAra! SL"},
                                              {"81-31", "Aragones Transports SA"},
                                              {"12-72", "Rocca SL"},
                                              {"99-10", "Rodriguez e Hijos SA"},
                                              {"00-65", "Rimbau Motors SL"} };
        JTable table = new JTable(rowData, new String[] {"Part No", "Provider"});
        
        JComboBox companyComboBox = new JComboBox(new Object[] {"AraAra! SL", "Aragones Transports SA", "Rocca SL", "Rodriguez e Hijos SA", "Rimbau Motors SL"});
        companyComboBox.setEditable(true);
        new S15WorkingBackspace(companyComboBox);

        // setup the ComboBoxCellEditor, DefaultCellEditor won't work!
        table.getColumnModel().getColumn(1).setCellEditor(new ComboBoxCellEditor(companyComboBox));
        
        table.setPreferredScrollableViewportSize(new Dimension(400, 100));
        JScrollPane scrollPane = new JScrollPane(table);
        
        contentPane.setLayout(new java.awt.FlowLayout());
        contentPane.add(scrollPane);
        contentPane.add(new JTextField("HALLO!"));
    }
    
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(3);
                createGUI(frame.getContentPane());
                frame.pack(); frame.setVisible(true);
            }
        });
    }   
}
           
         
    
  








Related examples in the same category

1.Shading Rows and Columns in a JTable Component
2.Shades every other column yellow
3.Using Built-In Cell Renderers and Editors in a JTable Component
4.Get Default cell Renderer
5.Get Default Cell Editor
6.Creating a Custom Cell Renderer in a JTable Component
7.Creating a Class-Based Custom Cell Renderer in a JTable Component
8.A slider renderer for volume values in a tableA slider renderer for volume values in a table
9.Table with a custom cell renderer and editor for the color dataTable with a custom cell renderer and editor for the color data
10.Table with initialized column sizes and a combo box editorTable with initialized column sizes and a combo box editor
11.StockTable 3: CellRendererStockTable 3: CellRenderer
12.Colored Table CellRendererColored Table CellRenderer
13.Change Table cell background with column renderer Change Table cell background with column renderer
14.Install different Table Renderer for even and odd rowsInstall different Table Renderer for even and odd rows
15.A table that allows the user to pick a color from a pulldown listA table that allows the user to pick a color from a pulldown list
16.MixerModel and sliders for rendering volume valuesMixerModel and sliders for rendering volume values
17.Table Editor: Editable Color ColumnTable Editor: Editable Color Column
18.Tab in and out JComboBox in JTable
19.Creating a Custom Table Cell Editor in a JTable Component
20.Preventing Invalid Values in a Cell in a JTable Component
21.Setting the Activation Click Count for a Table Cell Editor in a JTable Component
22.Using a JComboBox in a Cell in a JTable Component
23.Using a List JSpinner as a Cell Editor in a JTable Component
24.Rendering an image in a JTable column
25.This program demonstrates cell rendering and editing in a table.This program demonstrates cell rendering and editing in a table.