This is an example of customizing a GridControl to use some component other than a TextField. Specifically, this uses a ComboBoxControl, but the same principal applies to other controls such as RadioGroup, CheckBox, etc. This is a class source file (example_client.FrameMain.java) which was generated by the Business Components Data Form Wizard, then edited to customize the GridControl. It assumes a connection called scott (for the scott/tiger account) and a default BC4J project named example_bc4j based on the Dept and Emp tables. Notes: - The grid is intantiated - Constructor classes are contained in jbInit - The hidden objects that the grid creates are instantiated. - Call jbInit in the constructor, - In the try/catch block, add extra code to create your own reference to grid’s JTable. This represents the class. Then you can use cell rendered. Reference to the class and you can override the class methods. package example_client; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import oracle.dacf.control.swing.*; import oracle.dacf.control.tdg.*; import oracle.dacf.formatter.*; import oracle.dacf.dataset.*; import oracle.dacf.dataset.connections.*; import oracle.dacf.control.*; import oracle.dacf.layout.*; /* Added import for custom Grid */ import javax.swing.table.*; /** * This template contains a database-aware applet with a navigation bar * and a menu that is customised by the form generation wizard. * * @version 1.0 * @author Oracle Corp. * * Copyright (c) 1998-2000 Oracle Corporation */ public class FrameMain extends InfoFrame { //Define all the connection objects SessionInfo sessionInfo = new SessionInfo(); RowSetInfo DeptViewMasterIter = new RowSetInfo(); AttributeInfo DeptnoMasterCol = new AttributeInfo(java.sql.Types.NUMERIC); AttributeInfo DnameMasterCol = new AttributeInfo(java.sql.Types.VARCHAR); AttributeInfo LocMasterCol = new AttributeInfo(java.sql.Types.VARCHAR); RowSetInfo EmpViewDetailIter = new RowSetInfo(); AttributeInfo EmpnoDetailCol = new AttributeInfo(java.sql.Types.NUMERIC); AttributeInfo EnameDetailCol = new AttributeInfo(java.sql.Types.VARCHAR); AttributeInfo JobDetailCol = new AttributeInfo(java.sql.Types.VARCHAR); AttributeInfo MgrDetailCol = new AttributeInfo(java.sql.Types.NUMERIC); AttributeInfo HiredateDetailCol = new AttributeInfo(java.sql.Types.DATE); AttributeInfo SalDetailCol = new AttributeInfo(java.sql.Types.NUMERIC); AttributeInfo CommDetailCol = new AttributeInfo(java.sql.Types.NUMERIC); AttributeInfo DeptnoDetailCol = new AttributeInfo(java.sql.Types.NUMERIC); /** * This string is displayed by the form. It will be customised by the * form generator. * * @see #jbInit */ private String frameTitle = "Employee Information"; /** * This is the form's content pane. * * @see #jbInit */ private JPanel contentPane = new JPanel(); /** * This layout manager is used by the content pane. * * @see #jbInit */ private BorderLayout contentLayout = new BorderLayout(); /** * This panel holds the master and detail panels. * * @see #jbInit */ private JPanel formPanel = new JPanel(); /** * This layout is used by the formPanel. * * @see #jbInit */ private GridLayout formLayout = new GridLayout(0, 1); /** * This status bar is used by the form. * * @see #jbInit */ private StatusBarControl statusBar = new StatusBarControl(); /** * These controls define the menu structure of the form. * * @see #jbInit */ private JMenuBar menubarFrame = new JMenuBar(); private JMenu menuFile = new JMenu(); private JMenuItem itemFileExit = new JMenuItem(); private JMenu menuDatabase = new JMenu(); private JMenuItem itemDatabaseFirst = new JMenuItem(); private JMenuItem itemDatabasePrevious = new JMenuItem(); private JMenuItem itemDatabaseNext = new JMenuItem(); private JMenuItem itemDatabaseLast = new JMenuItem(); private JMenuItem itemDatabaseInsert = new JMenuItem(); private JMenuItem itemDatabaseDelete = new JMenuItem(); private JMenuItem itemDatabaseCommit = new JMenuItem(); private JMenuItem itemDatabaseRollback = new JMenuItem(); private JMenuItem itemFind = new JMenuItem(); private JMenu menuHelp = new JMenu(); private JMenuItem itemHelpAbout = new JMenuItem(); /** * This navigation bar is used by the master table of the form. * * @see #jbInit */ private NavigationBar masterNavBar = new NavigationBar(); /** * This panel holds the master panel and its navigation bar. */ private JPanel masterTable = new JPanel(); /** * This layout is used by the panel above. */ private BorderLayout masterTableLayout = new BorderLayout(); /** * This scroll pane is used by the master panel. */ private JScrollPane masterScroller = new JScrollPane(); /** * This panel holds the database aware controls for the master table. */ private JPanel masterPanel = new JPanel(); /** * This layout is used by the master panel. It may be modified by * the form generator. */ private ColumnLayout masterLayout = new ColumnLayout(); /** * This navigation bar is used by the detail table of the form. * * @see #jbInit */ private NavigationBar detailNavBar = new NavigationBar(); /** * This panel holds the detail panel and its navigation bar. */ private JPanel detailTable = new JPanel(); /** * This layout is used by the panel above. */ private BorderLayout detailTableLayout = new BorderLayout(); /** * This scroll pane is used by the detail panel. */ private JScrollPane detailScroller = new JScrollPane(); /** * This panel holds the database aware controls for the detail table. * It may be deleted by the form generator. */ private JPanel detailPanel = new JPanel(); /** * This layout is used by the detail panel. It may be either modified * or deleted by the form generator. */ private GridLayout detailLayout = new GridLayout(); /** * This information will be displayed in the about box. * * @see #helpAbout */ private String productName = "Product Name"; private String productVersion = "Version 0.0"; private String productCopyright = "Copyright (c) 1999"; private String[] aboutMessage = {productName, productVersion, productCopyright}; private String aboutTitle = "About " + productName; /** * Indicates whether queries should execute immediately. */ private boolean executeQueriesNow = true; //Fields to support database column: DEPTNO. private JPanel panelDEPTNO = new JPanel(); private ControlLayout layoutDEPTNO = new ControlLayout(); private JLabel labelDEPTNO = new JLabel(); private TextFieldControl controlDEPTNO = new TextFieldControl(); //Fields to support database column: DNAME. private JPanel panelDNAME = new JPanel(); private ControlLayout layoutDNAME = new ControlLayout(); private JLabel labelDNAME = new JLabel(); private TextFieldControl controlDNAME = new TextFieldControl(); //Fields to support database column: LOC. private JPanel panelLOC = new JPanel(); private ControlLayout layoutLOC = new ControlLayout(); private JLabel labelLOC = new JLabel(); private TextFieldControl controlLOC = new TextFieldControl(); //Fields to support a grid layout for the data. private GridControl detailGrid = new GridControl(); // added code for Custom Grid // sets up list of values for JComboBox // Note: this is a hard-coded list. For a dynamic list, create View Object which gets // the values and retrieve the data programmatically Object listVals[] = {"ANALYST","CLERK","MANAGER","PRESIDENT","SALESMAN"}; /** * Template's public constructor. * * @see #jbInit */ public FrameMain() { try { jbInit(); sessionInfo.publishSession(executeQueriesNow); /* Added code for custom Grid somewhere after DAC populates Form with sessionInfo.publishSession("..."); */ // get reference to Grid's JTable JTable myTable = detailGrid.getTable(); // get reference to a column TableColumn jobColumn = myTable.getColumn("Job"); // example of changing the header for this column jobColumn.setHeaderValue("Job Title"); // example of setting the width of this column jobColumn.setPreferredWidth(175); // custom TableCellRenderer (see definition below) TableCellRenderer myTCR = new ListCellRenderer(); // forces this column to use the custom Cell Renderer jobColumn.setCellRenderer(myTCR); // custom TableCellEditor TableCellEditor myTCE = new DefaultCellEditor(new JComboBox(listVals)); // forces this column to use the custom Cell Editor jobColumn.setCellEditor(myTCE); pack(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } // This method takes care of cleaning up when closing this window, // using the window 'X' addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { processWindowClosing(e); } }); } /** * Process the windowClosing event. * * @param event WindowEvent */ private void processWindowClosing(WindowEvent e) { sessionInfo.revokeSession(); InfoBusManager.getInstance().fireReleaseResources(this, this); sessionInfo.close(); System.exit(0); } /** * Template's initialiser. Creates the frame's UI. * * @throw Exception if any problems occur. */ public void jbInit() throws Exception { //Set up all the session information sessionInfo.setName("Session1"); sessionInfo.setAppModuleInfo(new ModuleInfo("example_bc4j", "Example_bc4jModule")); sessionInfo.setConnectionInfo(new LocalConnection("scott")); //Set up the view usage information DeptViewMasterIter.setName("DeptView"); DeptnoMasterCol.setName("Deptno"); DnameMasterCol.setName("Dname"); LocMasterCol.setName("Loc"); DeptViewMasterIter.setAttributeInfo(new ColumnInfo[] { DeptnoMasterCol, DnameMasterCol, LocMasterCol}); DeptViewMasterIter.setQueryInfo(new QueryViewInfo("DeptView")); DeptViewMasterIter.setSession(sessionInfo); //Set up the view usage information EmpViewDetailIter.setName("EmpView"); EmpnoDetailCol.setName("Empno"); EnameDetailCol.setName("Ename"); JobDetailCol.setName("Job"); MgrDetailCol.setName("Mgr"); HiredateDetailCol.setName("Hiredate"); SalDetailCol.setName("Sal"); CommDetailCol.setName("Comm"); DeptnoDetailCol.setName("Deptno"); EmpViewDetailIter.setAttributeInfo(new ColumnInfo[] { EmpnoDetailCol, EnameDetailCol, JobDetailCol, MgrDetailCol, HiredateDetailCol, SalDetailCol, CommDetailCol, DeptnoDetailCol}); EmpViewDetailIter.setQueryInfo(new QueryViewInfo("EmpView")); EmpViewDetailIter.setSession(sessionInfo); //Set up link association EmpViewDetailIter.setMasterLinkInfo(new ViewLinkInfo(DeptViewMasterIter, "example_bc4j.FkDeptnoLink")); setDataItemName("infobus:/oracle/Session1"); contentPane.setLayout(contentLayout); setContentPane(contentPane); setTitle(frameTitle); setSize(new Dimension(768, 338)); /* * Build the menu. */ setJMenuBar(menubarFrame); itemFileExit.setText("Exit"); itemFileExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { fileExit(e); } }); menuFile.add(itemFileExit); menuFile.setText("File"); menubarFrame.add(menuFile); itemDatabaseFirst.setText("First"); itemDatabaseFirst.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_FIRST); } }); menuDatabase.add(itemDatabaseFirst); itemDatabasePrevious.setText("Previous"); itemDatabasePrevious.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_PREV); } }); menuDatabase.add(itemDatabasePrevious); itemDatabaseNext.setText("Next"); itemDatabaseNext.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_NEXT); } }); menuDatabase.add(itemDatabaseNext); itemDatabaseLast.setText("Last"); itemDatabaseLast.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_LAST); } }); menuDatabase.add(itemDatabaseLast); menuDatabase.addSeparator(); itemDatabaseInsert.setText("Insert"); itemDatabaseInsert.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_INSERT); } }); menuDatabase.add(itemDatabaseInsert); itemDatabaseDelete.setText("Delete"); itemDatabaseDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_DELETE); } }); menuDatabase.add(itemDatabaseDelete); menuDatabase.addSeparator(); itemDatabaseCommit.setText("Commit"); itemDatabaseCommit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_COMMIT); } }); menuDatabase.add(itemDatabaseCommit); itemDatabaseRollback.setText("Rollback"); itemDatabaseRollback.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_ROLLBACK); } }); menuDatabase.add(itemDatabaseRollback); menuDatabase.addSeparator(); itemFind.setText("Find"); itemFind.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_FIND); } }); menuDatabase.add(itemFind); menuDatabase.setText("Database"); menubarFrame.add(menuDatabase); itemHelpAbout.setText("About"); itemHelpAbout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { helpAbout(e); } }); menuHelp.add(itemHelpAbout); menuHelp.setText("Help"); menubarFrame.add(menuHelp); /* * Set up the panels which will hold the master and detail controls. */ formPanel.setLayout(formLayout); masterTable.setLayout(masterTableLayout); masterPanel.setLayout(masterLayout); detailTable.setLayout(detailTableLayout); detailPanel.setLayout(detailLayout); getContentPane().add(statusBar, BorderLayout.SOUTH); getContentPane().add(formPanel, BorderLayout.CENTER); formPanel.add(masterTable, null); formPanel.setBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED)); masterTable.add(masterNavBar, BorderLayout.NORTH); masterTable.add(masterPanel, BorderLayout.CENTER); // To make the master panel scrollable, comment out the line above // and uncomment the following two lines. //masterTable.add(masterScroller, BorderLayout.CENTER); //masterScroller.getViewport().add(masterPanel); masterPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); formPanel.add(detailTable, null); detailTable.add(detailNavBar, BorderLayout.SOUTH); detailTable.add(detailPanel, BorderLayout.CENTER); //Code to connect the navigation bar to data. masterNavBar.setDataItemName("infobus:/oracle/Session1/DeptView"); masterNavBar.setHasInsertButton(true); masterNavBar.setHasDeleteButton(true); masterNavBar.setHasNavigationButtons(true); masterNavBar.setHasTransactionButtons(true); masterNavBar.setHasFindButton(true); //Code to support database column: DEPTNO. masterPanel.add(panelDEPTNO, new ControlConstraints(ControlConstraints.ALIGN_LEFT, 0, 0, -1, -1)); layoutDEPTNO.setArrangement(ControlLayout.ARRANGE_HORIZONTAL); panelDEPTNO.setLayout(layoutDEPTNO); panelDEPTNO.add(labelDEPTNO, new ControlConstraints(ControlConstraints.ALIGN_RIGHT, 0, 0, -1, -1)); labelDEPTNO.setText("DEPTNO:"); panelDEPTNO.add(controlDEPTNO, new ControlConstraints(ControlConstraints.ALIGN_LEFT, 0, 0, -1, -1)); controlDEPTNO.setDataItemName("infobus:/oracle/Session1/DeptView/Deptno"); controlDEPTNO.setColumns(15); controlDEPTNO.setToolTipText("Current entry in DEPTNO"); //Code to support database column: DNAME. masterPanel.add(panelDNAME, new ControlConstraints(ControlConstraints.ALIGN_LEFT, 0, 0, -1, -1)); layoutDNAME.setArrangement(ControlLayout.ARRANGE_HORIZONTAL); panelDNAME.setLayout(layoutDNAME); panelDNAME.add(labelDNAME, new ControlConstraints(ControlConstraints.ALIGN_RIGHT, 0, 0, -1, -1)); labelDNAME.setText("DNAME:"); panelDNAME.add(controlDNAME, new ControlConstraints(ControlConstraints.ALIGN_LEFT, 0, 0, -1, -1)); controlDNAME.setDataItemName("infobus:/oracle/Session1/DeptView/Dname"); controlDNAME.setColumns(15); controlDNAME.setToolTipText("Current entry in DNAME"); //Code to support database column: LOC. masterPanel.add(panelLOC, new ControlConstraints(ControlConstraints.ALIGN_LEFT, 0, 0, -1, -1)); layoutLOC.setArrangement(ControlLayout.ARRANGE_HORIZONTAL); panelLOC.setLayout(layoutLOC); panelLOC.add(labelLOC, new ControlConstraints(ControlConstraints.ALIGN_RIGHT, 0, 0, -1, -1)); labelLOC.setText("LOC:"); panelLOC.add(controlLOC, new ControlConstraints(ControlConstraints.ALIGN_LEFT, 0, 0, -1, -1)); controlLOC.setDataItemName("infobus:/oracle/Session1/DeptView/Loc"); controlLOC.setColumns(15); controlLOC.setToolTipText("Current entry in LOC"); //Code to connect the navigation bar to data. detailNavBar.setDataItemName("infobus:/oracle/Session1/EmpView"); detailNavBar.setHasInsertButton(true); detailNavBar.setHasDeleteButton(true); detailNavBar.setHasNavigationButtons(false); detailNavBar.setHasTransactionButtons(false); detailNavBar.setHasFindButton(false); //Code to support a grid layout for the data. detailPanel.add(detailGrid, null); detailGrid.setDataItemName("infobus:/oracle/Session1/EmpView"); // To make the detail panel scrollable, comment out the line above // and uncomment the following two lines. //detailTable.add(detailScroller, BorderLayout.CENTER); //detailScroller.getViewport().add(detailPanel); } /** * This method is called in response to the File|Exit menu item. * * @param e the event which caused this method to be called */ private void fileExit(ActionEvent e) { if (close()) { sessionInfo.revokeSession(); InfoBusManager.getInstance().fireReleaseResources(this, this); sessionInfo.close(); System.exit(0); } } /** * This method is called in response to the Help|About menu item. * * @param e the event which caused this method to be called */ private void helpAbout(ActionEvent e) { JOptionPane.showMessageDialog(this, aboutMessage, aboutTitle, JOptionPane.INFORMATION_MESSAGE); } /* inner class for custom CellRenderer */ class ListCellRenderer extends ComboBoxControl implements TableCellRenderer { public ListCellRenderer () { super(); } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setBackground(isSelected && !hasFocus ? table.getSelectionBackground() : table.getBackground()); setForeground(isSelected && !hasFocus ? table.getSelectionForeground() : table.getForeground()); setFont(table.getFont()); setModel(new DefaultComboBoxModel(listVals)); setSelectedItem(value); return this; } } }