JCombo in JTable

Hi all
I have looked at Steve and Franks Different Examples on this subject and have as yet not been able to implement right.
in some instances i have been able to get it to change in the database but not in the column ie does not render the value back
out problem is that the LOV databound drop down must display the name column but return the id coulum to the table
i have included the code below if you would like to take a look thanks
George
We are really gettin stuck now with this little issue. i mean i find it very strange that it is not documneted surely this is a regular requirment.
import com.toedter.calendar.JDateChooser;
import java.awt.*;
import javax.swing.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
import oracle.jbo.domain.Number;
import oracle.jbo.uicli.jui.*;
import oracle.jbo.uicli.controls.*;
import oracle.jbo.uicli.binding.*;
import oracle.jdeveloper.layout.*;
import oracle.adf.model.*;
import oracle.adf.model.binding.*;
import java.util.ArrayList;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import java.awt.Dimension;
import javax.swing.JPanel;
import java.awt.Rectangle;
import oracle.jdeveloper.layout.PaneLayout;
import oracle.jdeveloper.layout.PaneConstraints;
import javax.swing.JScrollPane;
import javax.swing.JList;
import javax.swing.ListModel;
import javax.swing.JTable;
import javax.swing.table.TableModel;
import javax.swing.JTextField;
import javax.swing.text.Document;
import javax.swing.JComboBox;
import javax.swing.ComboBoxModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import portaluniverse.ardcs2.model.am.common.InventoryService;
import portaluniverse.ardcs2.model.dao.FareProfileViewRowImpl;
import javax.swing.JButton;
import javax.swing.ButtonModel;
import javax.swing.event.CellEditorListener;
import java.util.EventObject;
import oracle.jbo.uicli.controls.JULabel;
import oracle.jbo.uicli.jui.JULabelBinding;
public class SchedulesPanel extends JPanel implements JUPanel {
// Panel binding definition used by design time
private JUPanelBinding panelBinding = new JUPanelBinding("SchedulesPanelUIModel");
private JPanel jPanel1 = new JPanel();
private JPanel jPanel2 = new JPanel();
private PaneLayout paneLayout1 = new PaneLayout();
private JScrollPane jScrollPane1 = new JScrollPane();
private JList jList1 = new JList();
private JScrollPane jScrollPane2 = new JScrollPane();
private JTable jTable1 = new JTable();
private JTextField jTextField1 = new JTextField();
private JComboBox jComboBox1 = new JComboBox();
private JTextField jTextField2 = new JTextField();
private JTextField jTextField3 = new JTextField();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JButton jButton3 = new JButton();
private JULabel jULabel1 = new JULabel();
private JULabel jULabel2 = new JULabel();
private JULabel jULabel3 = new JULabel();
private JULabel jULabel4 = new JULabel();
private JComboBox day1Com = new JComboBox();
* The default constructor for panel
public SchedulesPanel() {
* the JbInit method
public void jbInit() throws Exception {
this.setLayout(paneLayout1);
this.setSize(new Dimension(902, 616));
jPanel1.setSize(new Dimension(396, 274));
jPanel1.setLayout(null);
jPanel2.setLayout(null);
jScrollPane1.setBounds(new Rectangle(12, 55, 220, 545));
jScrollPane2.setBounds(new Rectangle(15, 240, 600, 265));
jTextField1.setText("jTextField1");
jTextField1.setBounds(new Rectangle(280, 35, 125, 20));
jComboBox1.setBounds(new Rectangle(280, 75, 125, 20));
jTextField2.setText("jTextField2");
jTextField2.setBounds(new Rectangle(280, 120, 125, 20));
jTextField3.setText("jTextField3");
jTextField3.setBounds(new Rectangle(280, 165, 125, 20));
jScrollPane1.getViewport().add(jList1, null);
jPanel1.add(jButton1, null);
jPanel1.add(jScrollPane1, null);
jPanel2.add(jULabel4, null);
jPanel2.add(jULabel3, null);
jPanel2.add(jULabel2, null);
jPanel2.add(jULabel1, null);
jPanel2.add(jButton3, null);
jPanel2.add(jButton2, null);
jPanel2.add(jTextField3, null);
jPanel2.add(jTextField2, null);
jPanel2.add(jComboBox1, null);
jPanel2.add(jTextField1, null);
jScrollPane2.getViewport().add(jTable1, null);
jPanel2.add(jScrollPane2, null);
this.add(jPanel1, new PaneConstraints("jPanel1", "jPanel1", PaneConstraints.ROOT, 0.5f));
this.add(jPanel2, new PaneConstraints("jPanel2", "jPanel1", PaneConstraints.RIGHT, 0.695f));
jList1.setModel((ListModel)panelBinding.bindUIControl("ScheduleView1", jList1));
jTable1.setModel((TableModel)panelBinding.bindUIControl("ScheduleView2", jTable1));
jTextField1.setDocument((Document)panelBinding.bindUIControl("FlightNo", jTextField1));
jComboBox1.setModel((ComboBoxModel)panelBinding.bindUIControl("SectorId", jComboBox1));
jTextField2.setDocument((Document)panelBinding.bindUIControl("DepartTime", jTextField2));
jTextField3.setDocument((Document)panelBinding.bindUIControl("ArriveTime", jTextField3));
jButton1.setBounds(new Rectangle(80, 15, 73, 23));
jButton1.setText("jButton1");
jButton1.setModel((ButtonModel)panelBinding.bindUIControl("Create", jButton1));
jButton1.setText("Create");
* Create a colum so that we can add a custon button to that column.
TableColumn splitCl = new TableColumn();
jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton3_actionPerformed(e);
jButton3.setBounds(new Rectangle(210, 555, 73, 23));
jButton3.setText("jButton3");
jButton2.setBounds(new Rectangle(45, 535, 73, 23));
jButton2.setText("jButton2");
jScrollPane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
splitCl.setHeaderValue("");
splitCl.setCellRenderer(new SplitButtonCellRenderer());
splitCl.setCellEditor(new SplitButtonCellEditor());
jTable1.addColumn(splitCl);
for(int i = 0; i == 7; i++){
jTable1.getColumnModel().getColumn(i).setPreferredWidth(-1);
jTable1.getColumnModel().getColumn(7).setPreferredWidth(250);
jTable1.getColumnModel().getColumn(8).setPreferredWidth(250);
jTable1.getColumnModel().getColumn(9).setPreferredWidth(100);
jButton2.setModel((ButtonModel)panelBinding.bindUIControl("Commit", jButton2));
jButton2.setText("Commit");
jULabel4.setBounds(new Rectangle(75, 120, 205, 20));
jULabel4.setText("jULabel4");
jULabel3.setBounds(new Rectangle(75, 165, 205, 20));
jULabel3.setText("jULabel3");
jULabel2.setBounds(new Rectangle(75, 75, 205, 20));
jULabel2.setText("jULabel2");
jULabel1.setBounds(new Rectangle(75, 35, 205, 20));
jULabel1.setText("jULabel1");
jULabel1.setText(panelBinding.findCtrlValueBinding("FlightNo1").getLabel());
jULabel2.setText(panelBinding.findCtrlValueBinding("SectorId1").getLabel());
jULabel3.setText(panelBinding.findCtrlValueBinding("DepartTime1").getLabel());
jULabel4.setText(panelBinding.findCtrlValueBinding("ArriveTime1").getLabel());
day1Com.setModel((ComboBoxModel)panelBinding.bindUIControl("Day1ComboBox", day1Com));
TableColumn day1Column = jTable1.getColumnModel().getColumn(0);
day1Column.setCellRenderer(new Day1RendererClass());
// day1Column.setCellEditor(new DefaultCellEditor(day1Com));
DefaultCellEditor df = new DefaultCellEditor(day1Com);
// day1Column.setCellEditor(new DefaultCellEditor(day1Com));
day1Column.setCellEditor(new Day1EditorClass());
public static void main(String [] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception exemp) {
exemp.printStackTrace();
SchedulesPanel panel = new SchedulesPanel();
panel.setBindingContext(JUTestFrame.startTestFrame("DataBindings.cpx", "null", panel, panel.getPanelBinding(), new Dimension(1024, 680)));
panel.revalidate();
* JUPanel implementation
public JUPanelBinding getPanelBinding() {
return panelBinding;
private void unRegisterProjectGlobalVariables(BindingContext bindCtx) {
JUUtil.unRegisterNavigationBarInterface(panelBinding, bindCtx);
private void registerProjectGlobalVariables(BindingContext bindCtx) {
JUUtil.registerNavigationBarInterface(panelBinding, bindCtx);
public void setBindingContext(BindingContext bindCtx) {
if (panelBinding.getPanel() == null) {
panelBinding = panelBinding.setup(bindCtx, this);
registerProjectGlobalVariables(bindCtx);
panelBinding.refreshControl();
try {
jbInit();
panelBinding.refreshControl();
} catch(Exception ex) {
panelBinding.reportException(ex);
* This class is used to add the button to the table.
class SplitButtonCellRenderer implements TableCellRenderer{
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JButton splitButton = new JButton("Split");
return splitButton;
* This class is used to override the cell editor and create a button in the cell
class SplitButtonCellEditor implements TableCellEditor{
public void cancelCellEditing() {
// TODO: Implement this javax.swing.CellEditor abstract method
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
JButton splitButton = new JButton("Split");
final String effectiveDate = table.getValueAt(row,7).toString();
final String endDate = table.getValueAt(row,8).toString();
splitButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
Date effectiveDateD = sdf.parse(effectiveDate);
Date endDateD = sdf.parse(endDate);
* Custom login to check that the dates are in valid time period
* first date Not < start
* > end
boolean cont= false;
do{
SplitDialogForSchedulesPanel sp1 = new SplitDialogForSchedulesPanel(null,"Split Schedule",true);
sp1.show();
JDateChooser newStartDateS = sp1.dateChooser1;
JDateChooser newEndDateS = sp1.dateChooser2;
Date newStartDate =newStartDateS.getDate();
Date newEndDate = newEndDateS.getDate();
// boolean a = (newStartDate.getTime() < newEndDate.getTime());
// a = (newStartDate.getTime() > effectiveDateD.getTime());
// a = (newStartDate.getTime() < endDateD.getTime());
// a = (newEndDate.getTime() > effectiveDateD.getTime());
// a = (newEndDate.getTime() < endDateD.getTime());
// if((newStartDate.getTime() < newEndDate.getTime()) &&(newStartDate.getTime() > effectiveDateD.getTime()) && (newStartDate.getTime() < endDateD.getTime()) && (newEndDate.getTime() > effectiveDateD.getTime()) && (newEndDate.getTime() < endDateD.getTime()) ){
((InventoryService)panelBinding.getDataControl().getApplicationModule()).splitSchedules(newStartDate, newEndDate);
cont = true;
}while(!cont);
// ((InventoryService)panelBinding.getDataControl().getApplicationModule()).setNamesForSchedules();
catch (Exception f) {
return splitButton;
public Object getCellEditorValue() { return null;  }
public boolean isCellEditable(EventObject anEvent) { return true; }
public void removeCellEditorListener(CellEditorListener l) {
// TODO: Implement this javax.swing.CellEditor abstract method
public boolean shouldSelectCell(EventObject anEvent) {
// TODO: Implement this javax.swing.CellEditor abstract method
return true;
public boolean stopCellEditing() {
// TODO: Implement this javax.swing.CellEditor abstract method
return false;
public void addCellEditorListener(CellEditorListener l) {
// TODO: Implement this javax.swing.CellEditor abstract method
private void jButton3_actionPerformed(ActionEvent e) {
((InventoryService)panelBinding.getDataControl().getApplicationModule()).commitOnSchedule();
* Overriden class for day 1 so that a combo box can be displayed
public class Day1RendererClass extends DefaultTableCellRenderer{
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JComboBox day1Combo = new JComboBox();
System.out.println("VAL ==== "+value);
System.out.println(value.getClass().getName());
day1Combo.addItem(((FareProfileViewRowImpl)day1Com.getSelectedItem()).getName());
day1Combo.setSelectedItem(((FareProfileViewRowImpl)day1Com.getSelectedItem()).getName());
return day1Combo;
public class Day1EditorClass implements TableCellEditor{
// JComboBox day1Combo = new JComboBox();
public void addCellEditorListener(CellEditorListener l) {
public void cancelCellEditing() {
public Object getCellEditorValue() {
// try {
// return new Number(((FareProfileViewRowImpl)day1Com.getSelectedItem()).getId().toString());
// catch (Exception e) {
return ((FareProfileViewRowImpl)day1Com.getSelectedItem()).getName();
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
JComboBox com = day1Com;
// com.setModel((ComboBoxModel)panelBinding.bindUIControl("Day1ComboBox", com));
return com;
public boolean isCellEditable(EventObject anEvent) {
return true;
public void removeCellEditorListener(CellEditorListener l) {
public boolean shouldSelectCell(EventObject anEvent) {
return true;
public boolean stopCellEditing() {
return false;
Please not this is the entire source of the class
thanks
please help would really be appreciated

ok i have implemented steves example
the problem is that the combobox is returning type row that is the row that it bound via the vo bound to the LOV.
it should be returnin number.
so i can select the drop down but when i click on and option i get
oracle.jbo.domain.DataCreationException: JBO-25009: Cannot create an object of type:oracle.jbo.domain.Number with value:portaluniverse.ardcs2.model.dao.FareProfileViewRowImpl@2
     at oracle.jbo.domain.TypeFactory.get(TypeFactory.java:747)
     at oracle.jbo.domain.TypeFactory.getInstance(TypeFactory.java:85)
     at oracle.jbo.server.AttributeDefImpl.convertToJava(AttributeDefImpl.java:1339)
     at oracle.jbo.server.ViewRowImpl.setAttribute(ViewRowImpl.java:832)
     at oracle.adf.model.binding.DCDataControl.setAttributeInRow(DCDataControl.java:1745)
     at oracle.adf.model.bc4j.DCJboDataControl.setAttributeInRow(DCJboDataControl.java:1548)
     at oracle.jbo.uicli.binding.JUCtrlValueBinding.setAttributeInRow(JUCtrlValueBinding.java:615)
     at oracle.jbo.uicli.binding.JUCtrlValueBinding.setAttributeInRow(JUCtrlValueBinding.java:523)
     at oracle.jbo.uicli.jui.JUTableBinding$JUTableModel.setValueAt(JUTableBinding.java:1219)
     at oracle.jbo.uicli.jui.JUTableBinding.setValueAt(JUTableBinding.java:654)
     at oracle.jbo.uicli.jui.JUTableSortModel.setValueAt(JUTableSortModel.java:555)
     at javax.swing.JTable.setValueAt(JTable.java:1794)
     at javax.swing.JTable.editingStopped(JTable.java:3167)
     at portaluniverse.ardcs2.gui.inventory.SchedulesPanel$1.editingStopped(SchedulesPanel.java:70)
     at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:124)
     at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:329)
     at javax.swing.DefaultCellEditor$3.stopCellEditing(DefaultCellEditor.java:139)
     at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:214)
     at javax.swing.DefaultCellEditor$EditorDelegate.actionPerformed(DefaultCellEditor.java:346)
     at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1197)
     at javax.swing.JComboBox.setSelectedItem(JComboBox.java:561)
     at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:597)
     at javax.swing.plaf.basic.BasicComboPopup$ListMouseHandler.mouseReleased(BasicComboPopup.java:749)
     at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:232)
     at java.awt.Component.processMouseEvent(Component.java:5100)
     at javax.swing.plaf.basic.BasicComboPopup$2.processMouseEvent(BasicComboPopup.java:452)
     at java.awt.Component.processEvent(Component.java:4897)
     at java.awt.Container.processEvent(Container.java:1569)
     at java.awt.Component.dispatchEventImpl(Component.java:3615)
     at java.awt.Container.dispatchEventImpl(Container.java:1627)
     at java.awt.Component.dispatchEvent(Component.java:3477)
     at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
     at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
     at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
     at java.awt.Container.dispatchEventImpl(Container.java:1613)
     at java.awt.Window.dispatchEventImpl(Window.java:1606)
     at java.awt.Component.dispatchEvent(Component.java:3477)
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
     at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
## Detail 0 ##
java.lang.NumberFormatException: For input string: "rse.ardcs2.model.dao.FareProfileViewRowImpl@2"
     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
     at java.lang.Integer.parseInt(Integer.java:468)
     at java.lang.Integer.parseInt(Integer.java:518)
     at java.math.BigDecimal.<init>(BigDecimal.java:207)
     at oracle.jbo.domain.Number.<init>(Number.java:286)
     at sun.reflect.GeneratedConstructorAccessor3.newInstance(Unknown Source)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
     at oracle.jbo.domain.TypeConvMapEntry.convert(TypeConvMapEntry.java:73)
     at oracle.jbo.domain.TypeFactory.get(TypeFactory.java:715)
     at oracle.jbo.domain.TypeFactory.getInstance(TypeFactory.java:85)
     at oracle.jbo.server.AttributeDefImpl.convertToJava(AttributeDefImpl.java:1339)
     at oracle.jbo.server.ViewRowImpl.setAttribute(ViewRowImpl.java:832)
     at oracle.adf.model.binding.DCDataControl.setAttributeInRow(DCDataControl.java:1745)
     at oracle.adf.model.bc4j.DCJboDataControl.setAttributeInRow(DCJboDataControl.java:1548)
     at oracle.jbo.uicli.binding.JUCtrlValueBinding.setAttributeInRow(JUCtrlValueBinding.java:615)
     at oracle.jbo.uicli.binding.JUCtrlValueBinding.setAttributeInRow(JUCtrlValueBinding.java:523)
     at oracle.jbo.uicli.jui.JUTableBinding$JUTableModel.setValueAt(JUTableBinding.java:1219)
     at oracle.jbo.uicli.jui.JUTableBinding.setValueAt(JUTableBinding.java:654)
     at oracle.jbo.uicli.jui.JUTableSortModel.setValueAt(JUTableSortModel.java:555)
     at javax.swing.JTable.setValueAt(JTable.java:1794)
     at javax.swing.JTable.editingStopped(JTable.java:3167)
     at portaluniverse.ardcs2.gui.inventory.SchedulesPanel$1.editingStopped(SchedulesPanel.java:70)
     at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:124)
     at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:329)
     at javax.swing.DefaultCellEditor$3.stopCellEditing(DefaultCellEditor.java:139)
     at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:214)
     at javax.swing.DefaultCellEditor$EditorDelegate.actionPerformed(DefaultCellEditor.java:346)
     at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1197)
     at javax.swing.JComboBox.setSelectedItem(JComboBox.java:561)
     at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:597)
     at javax.swing.plaf.basic.BasicComboPopup$ListMouseHandler.mouseReleased(BasicComboPopup.java:749)
     at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:232)
     at java.awt.Component.processMouseEvent(Component.java:5100)
     at javax.swing.plaf.basic.BasicComboPopup$2.processMouseEvent(BasicComboPopup.java:452)
     at java.awt.Component.processEvent(Component.java:4897)
     at java.awt.Container.processEvent(Container.java:1569)
     at java.awt.Component.dispatchEventImpl(Component.java:3615)
     at java.awt.Container.dispatchEventImpl(Container.java:1627)
     at java.awt.Component.dispatchEvent(Component.java:3477)
     at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
     at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
     at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
     at java.awt.Container.dispatchEventImpl(Container.java:1613)
     at java.awt.Window.dispatchEventImpl(Window.java:1606)
     at java.awt.Component.dispatchEvent(Component.java:3477)
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
     at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
thanks
George

Similar Messages

  • Add Jcombo in Jtable at run time

    hello,
    i want to add jcombo box in jtable every cell & i also add column in run time.proble is when i add new column that time last column combo is add but prievious column its remove automatic.
    so give me some code & where i can get see good example for add combo in jtable.
    thanks

    hi j-rg,
    It was really appreaciating to c ur reply, regarding the specific problem.Actually wht i was facing the peoblem, Am adding a colomn in the run time and in that column am adding a combo in each cells of that column.AS i was expecting am able to add a new colum in th erum time with the combo in each cells of that column,now when am adding another column in the run time am getting all the required things,but the problem is " in the previous cloumn am not getting that combo"(only the combo is been added in the last column).
    What am expecting is the combo should be there in each cell of the column(all columns)
    Am also sending the code wht am using, plz have a look below,
    df1.addColumn(result);
         TableColumn aa= tb1.getColumnModel().getColumn(tb1.getColumnCount()-1);
         aa.setCellEditor(new DefaultCellEditor(comboBox));
    wating for ur reply
    thanks and regards
    sandeep

  • Displaying the contents of JCombo in JTable

    <Re-post from 'New To Java' forum>
    Hi,
    I have created a JTable which loads a list of Strings into one of its fields as a JComboBox. The JComboBox defaults to one of the items in the list of String when the frame is loaded.
    Problems:
    1. When the frame is loaded, the combo box loads the list of Strings (when combobox is dropped down) but does not display any of the items in the String list, and not even the default value at loading.
    2. When the item is selected via the "down arrow", the combo box still does not display the item selected. However, debugging codes to print the item selected to console were correctly executed. The combo box only displays the selection when the precise cell gets focus without the drop down.
    Can someone help with this by showing me the way (with codes) to do the above? Thanks!

    http://www.exampledepot.com/egs/javax.swing.table/ComboBox.html

  • Probem to adding JCombo in HTable(UTGENT)

    Hello,
    i want to add jcombo in jtable.accually in my table i add column in run time & every column when i add (evry cell) want to combo.
    but problem is when i add column that time last column i find every cell have combo,but previous column i lost combo.
    my coding is
    defaulttablemodel.addColumn("column name");
         TableColumn aa= table.getColumnModel().getColumn(table.getColumnCount()-1);
         aa.setCellEditor(new DefaultCellEditor(comboBox));
    but i got bug in this code, so plz give me answer what i do?
    I want every cell have combo in all column.
    Thanks
    sandeep

    note to self: think before posting question -> i figured out why of to banging head in wall

  • Sortable jtable with jcombo having different values

    Hi,
    I have a contacts list with name, addrerss etc., and telephone numbers where each contact can have several telephone numbers.
    The data is stored in a Derby DB in two tables with a PK and FK relationship. I need to load all the Contact fields in to a JTable where one of the columns will be the JCombos with telephone number(s) for that paticular contact.
    I have studied two neat sample code segments posted by a senior mrmber "camickr" at;
    [http://forum.java.sun.com/thread.jspa?forumID=57&threadID=637581 |http://forum.java.sun.com/thread.jspa?forumID=57&threadID=637581 ]
    Also another by " skdaga " at;
    [http://forums.sun.com/thread.jspa?threadID=749031&messageID=4284078|http://forums.sun.com/thread.jspa?threadID=749031&messageID=4284078]
    both are solid working examples.
    My problem is that I need to let the user to sort the table by columns and also filter by a text box entry. Meaning, the Combo boxes cannot have a fixed row index.
    Could someone advice if this is possible or I should use some other approach.
    Thanking you in advance,

    Hi camickr;
    Many thanks for your kind reply. I have managed to slightly modify your code to load the combos of individual telephone numbers dynamically.
    I have done so by returning a TableCellEditor from the public TableCellEditor getCellEditor(int row, int column) method, in place of storing the
    DefaultCellEditor dce1 = new DefaultCellEditor( comboBox1 ); etc., in an ArrayList.
    It goes as this. Following method is called by the return statement.
    private TableCellEditor createCellEditorWithCombo(int contactId) {
            JComboBox cmbNumbers = new JComboBox( <passed a Vector here thro' a PreparedStatement from the DB>);
            DefaultCellEditor editor = new DefaultCellEditor(cmbNumbers);
            return (TableCellEditor)editor;
        }The contactId of course could be easily desiphered from the "row" parameter then and there.
    I will follow your advice on the sorting part (on which I am yet to read the API fully) and get back with the result. Btw, I use the JDK 1.6u7 with Netbeans 6.1
    Thanking you once again for your great contributions,
    ViKARLL
    NB: By the way;
    camickr wrote:
    Well, if you look at my example you will note it uses the convertColumnIndexToModel(...). So you need to do the same thing for the row.It looks like you are referring to a diffrent post by you, since your example I worked on does not contain this method ??
    Edited by: ViKARLL on Sep 13, 2008 4:19 AM

  • JTable JCombo renderer ignores setForeground

    The setForeground calls in the renderer are ignored. The JCombo values are displayed in JTable foreground color. Any fix for this?
    Thanks
    class ComboCellRenderer extends DefaultTableCellRenderer implements TableCellRen
    derer
      protected static Border m_noFocusBorder    =    new
      EmptyBorder (1,                1,              1,              1);
      protected static    Border    m_focusBorder =
      UIManager.getBorder("Table.focusCellHighlightBorder");
      public
      ComboCellRenderer
      public Component
      getTableCellRendererComponent
      (JTable table,hasFocus,
       int nRow, int nCol)
        Color fg=new Color(255,0,0);
        //ColorData cvalue = new ColorData(value);
        if (table.getModel().getValueAt(nRow, 11).toString().trim().equals("Lucent")
          setForeground(fg);
        else if (table.getModel().getValueAt(nRow, 11).toString().trim().equals("Nor
    tel"))
          setForeground(Color.blue);
        else
          setForeground(Color.green);
        setBackground
          (isSelected && !hasFocus ?         table.getSelectionBackground() : table.
    getBackground ());
        //setForeground (isSelected && !hasFocus ?
        //   table.getSelectionForeground() : table.getForeground ());
        setFont (table.getFont ());
        //setBorder (hasFocus ? m_focusBorder : m_noFocusBorder);
        int rowHeight =     getPreferredSize().height; return this;
      public String getToolTipText (MouseEvent event)
        return null;
    } //class ComboCellRendererif (table.getRowHeight(nRow) < rowHeight)
    table.setRowHeight (nRow, rowHeight);
    Object value,
    boolean
    isSelected,
    boolean

    OOPS...
    It seems that through a cut-and-paste error, I lost the first few lines of my code in the previous post. Here it is in its entirety for anyone who is interested...
    class CheckBoxTableCellRenderer extends JCheckBox implements TableCellRenderer {
      Border noFocusBorder;
      Border focusBorder;
      public CheckBoxTableCellRenderer() {
        super();
        setContentAreaFilled(true);  // use this instead of setOpaque()
        setBorderPainted(true);
        setHorizontalAlignment(SwingConstants.CENTER);
        setVerticalAlignment(SwingConstants.CENTER);
      public Component getTableCellRendererComponent(JTable table, Object value,
                                                     boolean isSelected,
                                                     boolean hasFocus,
                                                     int row, int column) {
        if(table == null) {
        else {
          if (isSelected) {
            setForeground(table.getSelectionForeground());
            setBackground(table.getSelectionBackground());
          else {
            setForeground(table.getForeground());
            setBackground(table.getBackground());
          setEnabled(table.isEnabled());
          setComponentOrientation(table.getComponentOrientation());
          if (hasFocus) {
            if (focusBorder == null) {
              focusBorder = UIManager.getBorder("Table.focusCellHighlightBorder");
            setBorder(focusBorder);
          else {
            if (noFocusBorder == null) {
              if (focusBorder == null) {
                focusBorder = UIManager.getBorder("Table.focusCellHighlightBorder");
              if (focusBorder != null) {
                Insets n = focusBorder.getBorderInsets(this);
                noFocusBorder = new EmptyBorder(n);
            setBorder(noFocusBorder);
          setSelected(Boolean.TRUE.equals(value));
        return this;
    }

  • JTable in JCombo

    i want to display JTable in JComboBox
    please see this code and tell me the mistake
    import java.awt.*;
    import java.lang.Object.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.event.*;
    import javax.swing.plaf.basic.*;
    import javax.swing.plaf.metal.*;
    import java.util.*;
    import javax.swing.table.*;
    //My Custom ComboBox
    class myCombo extends JComboBox{
    protected int popupWidth;
    public myCombo(Vector vItems)
    //super(vItems);
    this.addItem(vItems);
    setUI(new myComboDefaultUI());
    //setBorder(new EtchedBorder());
    public Dimension getPopupSize() {
    Dimension size = getSize();
    if (popupWidth < 1) popupWidth = size.width;
    return new Dimension(popupWidth,
    size.height);
    //UI class controls popup size and location
    public class myComboDefaultUI extends BasicComboBoxUI{
    protected ComboPopup createPopup(){
    BasicComboPopup popup = new BasicComboPopup(comboBox){
    protected JScrollPane createScroller() {
    JScrollPane jscrollpane = new JScrollPane( list,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED );
    return jscrollpane;
    }//end of method createScroller
    public void show() {
    Dimension popupSize = ((myCombo)comboBox).getPopupSize();
    popupSize.setSize( popupSize.width,
    getPopupHeightForRowCount(
    comboBox.getMaximumRowCount() ) );
    //computes popup size
    Rectangle popupBounds = computePopupBounds( 0,
    comboBox.getBounds().height, popupSize.width, popupSize.height);
    list.invalidate();
    int selectedIndex = comboBox.getSelectedIndex();
    if ( selectedIndex == -1 ) {
    list.clearSelection();
    } else {
    list.setSelectedIndex( selectedIndex );
    list.ensureIndexIsVisible( list.getSelectedIndex() );
    setLightWeightPopupEnabled(
    comboBox.isLightWeightPopupEnabled() );
    show( comboBox, popupBounds.x,
    popupBounds.y);
    return popup;
    }//end of method createPopup
    }//end of inner class myComboUI
    //My custom Renderer
    class Renderer extends javax.swing.JTable implements
    ListCellRenderer {
    int nTotalRows;
    static int nRunningRows=0;
    String columnNames[];
    /** Creates new Renderer */
    public Renderer() {
    super();
    public Renderer(int nRows, int nCols, int nListRows)
    //super(nRows,nCols);
    nTotalRows = nListRows;
    public Component getListCellRendererComponent(JList
    p1,Object rowData,int index,boolean isSelected,boolean
    cellHasFocus) {
    //FDFH fdfh;
    //if (value instanceof FDFH)
    Vector value = (Vector) rowData;
    this.setModel(new DefaultTableModel(value.size(),((Vector)value.elementAt(0)).size())) ;
    System.out.println("Value is:" + value.toString()+ ", index:" + index);
    //fdfh = (FDFH)value;
    //Put values into JTable cells
    System.out.println(value+"shekar");
    if(index != -1)
    {     for(int i=0;i<value.size();i++)
         Vector v1=(Vector)value.elementAt(i);
         for ( int j = 0; j < v1.size(); j++ ) {
         getModel().setValueAt( v1.elementAt(j), i, j ) ;
    /*     if(index<2)
         getModel().setValueAt(value,0,index);
         else{
         getModel().setValueAt(value,1,index-2);
    //getModel().setValueAt(value,0,1);
    //getModel().setValueAt(value,0,2);
    //Set JTable Size
    //setSize(700,300);
    setRowSelectionAllowed(true);
    return this;
    public class Combo2 extends JFrame{
         JPanel p=new JPanel();
         public myCombo com;
         protected int popupWidth;
         public Combo2(){
              String columnNames[][] ={{"Name", "Vorname", "Ort", "PLZ"},
              {"Mark", "Andrews", "Baseball", "1"},
              {"Tom", "Ball", "Football", "2"},
              {"Alan", "Chung", "Baseball", "3"},
              {"Jeff", "Dinkins", "Football", "4"},
              {"Amy", "Fowler", "Hockey", "5"}};
         Vector v=new Vector();
         for(int i=0;i<columnNames.length;i++)
              Vector v1=new Vector();
         for(int j=0;j<columnNames.length;j++)
         v1.addElement(columnNames[i][j]);
              v.addElement(v1);
         com=new myCombo(v);
         Renderer renderer =new Renderer(6,4,1);
         com.setRenderer(renderer);
         p.add(com);
         //com.setUI(new myComboDefaultUI());
         this.getContentPane().add(p);
         this.setSize(500,200);
         this.setVisible(true);
         public static void main (String [] arg){
              Combo2 obj=new Combo2();
    Hope this helps.
    Regards,
    chandru

    Hi,
    What is not working???
    JRG

  • How to put data in JTable from database

    hi everyone,
    i want to query the databse and put the result in the JTable and if possible i want to edit some information. For example: i have 5 records in the database query them and place them in JTable and each record has its own status. if i want to change the status For Example: the status of the 4 records are "Cleared" and the other one is "RELEASEd" so if i have JCombo Box to set the 4 records in to RELEASED status and then save the changes is that possible?
    thank you
    dhing

    In [url /thread.jsp?forum=54&thread=387565]this thread I describe how to use a result set as a basis for table data. Check some database tutorials for information on getting a result set.

  • How to load data from text.txt fiel and tokenize it into JCombo box???

    Hi Everyone,
    I am new to Java and Netbeans. I am working on the same GUI project and need your Help!!
    I have two queries and since i am new,please if possible explain step by step
    1.) How can I load the contents of data stored in sometext.txt file when i click the JCombo box]?? Also, if i enter a new string not existing in text, it should display a message and add the new entered data into the sometext.txt file.
    2.) How can i input the contents of table.txt file (which has characters seperated by Tab) into a JTable into specific rows and columns??. Again, the txt should add and update the new entered data.
    I dont want to use any databse connection!!
    Explainations with Examples/Attachments will be greatly and truly appreciated
    Please Please Help me ASAP as i have to submit this assignment by next week!!

    hi camickr,
    I tried to load a file into Jtable. I have used random access file method to read a large text file seperated by tabs. When i tried to run the file, i was unable to load the data from the file. i guess i am missing the link between custom table and the default table. Can you please help me?
    The complete code is attached below:.(The reason i am attaching the whole code is ..so that you can check me where i am going wrong, please dont mind!!)
    package javaapplication;
    import java.io.*;
    import java.util.ArrayList;
    import javax.swing.table.AbstractTableModel;
    public class table extends javax.swing.JFrame {
    /** Creates new form table */
    public class FileTableModel extends AbstractTableModel {
    RandomAccessFile raf;
    ArrayList<Long> lineToPos = new ArrayList<Long>();
    int columnCount = -1;
    public FileTableModel(String fileName) {
    try {
    raf = new RandomAccessFile(new File(fileName), "C://temp.txt");
    lineToPos.add(new Long(0));
    String line = null;
    while ((line = raf.readLine()) != null) {
    if (columnCount == -1)
    columnCount = line.split(" ").length;
    lineToPos.add(new Long(raf.getFilePointer()));
    lineToPos.remove(lineToPos.size()-1);
    } catch (Exception e) {
    e.printStackTrace();
    protected void finalize() throws Throwable {
    super.finalize();
    raf.close();
    public int getColumnCount() {
    return columnCount;
    public int getRowCount() {
    return lineToPos.size();
    public Object getValueAt(int rowIndex, int columnIndex) {
    try {
    raf.seek(lineToPos.get(rowIndex).longValue());
    String line = raf.readLine();
    String[] strs = line.split(" ");
    return strs[columnIndex];
    } catch (IOException e) {
    e.printStackTrace();
    return null;
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    jTable1 = new javax.swing.JTable();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jTable1.setModel(jTable1.getModel());
    jScrollPane1.setViewportView(jTable1);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(15, Short.MAX_VALUE))
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(14, Short.MAX_VALUE))
    pack();
    }// </editor-fold>
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new table().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTable jTable1;
    // End of variables declaration
    }

  • JSPinner in a JTable Cell

    Plz let me know how to add a JSpinner component in a JTable cell.I was able to add JCOmbo and Jtextfield,,but i need to add a JSpinner...how to do that...
    regds
    Subhash.K

    thank you for responce
    Object[][] data1 = {
                              {"Datum", new Spinner(new SpinnerNumberModel(200,1,255,1)),""}, //this sets the innitial value to 200
                             {"ActiveAntenna", new Boolean(true),""}
    String[] colname1 = {"Variable","Value","Unit"};do you have an idea how to set the value, min, and step in my Spinner class
    regards
    gebi

  • Please help! How to add a combobox on a jtable

    Hi, I have seen on google and here many codes to add a combobox in a jtable but none of them seem to work, I need the urgently.
    My problem is that I must add a comboBox or a JComboBox to a cell inside a JTable on a predefined column. It means that on the column 2 I must add diferent comboboxes for eac row. How can I do it, please help.

    The celleditor is the component shown and the cellrenderer is the first render of a component in the cell and dont have to be the same jcombo box?
    The code on ther post does this:?
    returning a diferent combobox for all the cells on the column depending on the row selected, but as long as only one cell can be selected at a time it seems to hace different jcomboboxes added a time?
    Is there anyway to render any combobox with different values, my program must let the user chose the teacher it want to teach a definen subject, so the combo must have the teacher of a subject loaded on a database, the combos are not constants. I guess I can manage to use the way you showed me, but is there anyway to render a combo just by adding it to a cell! maybe doing changes to the tablemodel or things like that?

  • Updating JTable from data from resultset

    I have an athletics database, where the user updates an event and round e.g. 100M run Round 1. I then have a query which returns the 3 fastest times from each round for whatever event.
    Now on my JTable gui, the user chooses what event and round to update through 2 JCombo boxes, one for events, one for rounds. Now if the user chooses the round name final, i need the JTable to update the table with the three fastest times from rounds 1, 2 and 3.
    Whats the best way to do this? I was thinking putting all the different result sets into an array, and then through an if loop have somthing like
    if(roundType.equals (final))then in the body of this loop, create an instance of my JTable setting the rows for each column the the resultset data.
    Is this the right approach or any other advise?
    cheers

    You probably defined the "table" variable twice. Once as a class variable and once as a local variable and your "insertValue" method is referring to the wrong variable and therefore updating the wrong table.

  • Cell rendering the JRadioButton in JTable(Most Urgent)

    Hai guys,
    How can I rendering the JRadioButton in JTable ?
    In JTable JCombo,JTexrField,JTextArea to be rendered.But I can't rendering the JRadioButton.
    This is urgent for me.
    By kavi...

    http://onesearch.sun.com/search/onesearch/index.jsp?qt=JRadioButton+in+JTable&qp=siteforumid%3Ajava57&chooseCat=allJava&col=developer-forums&site=dev

  • Identifying JTable component & populating

    Hi all,
    I have a JTable which is pre-populated using a TableFormat. What I need to do later in the code (once the table has been drawn) is identify what components are in the table and then do something with these components.
    For example if my JTable contains a JCombo box called "combo" and a text field called "text" I would like to get the combo component and then populate it with some values
    Any suggestions much appreciated,

    Seems like creating your own table model is the solution you are looking for.
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

  • Problem hotspot with Jtable

    i am sorry may english, my English is not very good, my natural language is Spanish.
    I am using jtable, i beginning it with elements null and i fill it after. But when i am going to fill it i get the next error
    Java VM: Java HotSpot(TM) Client VM (1.4.0-b92 mixed mode)
    # Error ID: 434F444523414348450E43505000BE
    # Problematic Thread: prio=7 tid=0x0AB83010 nid=0x7f8 runnable
    but i use -server for running, then i don`t get the error.
    somebory can help me.

    here is the complete class.
    I call first the method
    iniciaTablaVector(
    boolean puede_editar,
    boolean puede_sortear,
    boolean puede_seleccionar)
    after i get the data from the database and add them into the vectors i call
    the method
    asignaDatosTabla(java.util.Vector vector_campos_usar,
    java.util.Vector vector_campos_usar_i,
    java.util.Vector vector_datos,
    java.util.Vector vector_datos_campos)
    package version01;
    * TITULOS: Programas Boca
    * DESCRIPCION Programas Generales
    * DERECHO RESERVADO Derechos reservado 2001
    * COMPANIA Sistemas Boca
    * @AUTORES Jos� Alberto Felipe y Jos� Luis Marte
    * @VERSION 1.0
    public class ManejoTablaVector02 //extends javax.swing.JTable
    javax.swing.JTable vista_tabla;
    miModeloTabla mimodelotabla;
    private boolean DEBUG = true;
    private boolean PUEDE_SEL_COLUMNA = false;
    private boolean PUEDE_SEL_FILA = true;
    private int fila_sel;
    java.awt.Container frame_usar;
    ManejoParametros manejoparametros;
    java.util.Vector vector_columnas, vector_campos_usar,vector_campos_usar_i;
    java.util.Vector vector_datos,vector_datos_campos ;
    javax.swing.JComponent[] campos;
    java.util.Vector vector_campos;
    java.util.TreeMap map_campos;
    ManejoPantalla manejopantalla;
    javax.swing.ListSelectionModel modelo_fila_sel;
    boolean puede_editar;
    boolean puede_sortear;
    boolean puede_seleccionar;
    //Object[] valores_largo;
    //Class[] clase_columnas;
    java.util.Vector valores_largo;
    java.util.Vector clase_columnas;
    public ManejoTablaVector02(java.awt.Container frame_usar,
    ManejoParametros manejoparametros,
    // java.util.Vector vector_datos,
    // java.util.Vector vector_datos_campos,
    // java.util.Vector vector_campos_usar,
    // java.util.Vector vector_campos_usar_i,
    javax.swing.JComponent[] campos,
    java.util.Vector vector_campos,
    java.util.TreeMap map_campos)
    this.frame_usar = frame_usar;
    this.manejoparametros = manejoparametros;
    /* this.vector_campos_usar = vector_campos_usar;
    this.vector_campos_usar_i = vector_campos_usar_i;
    if (manejoparametros.datos_leidos_tablas == null)
    manejoparametros.datos_leidos_tablas = new java.util.Vector();
    if (manejoparametros.datos_leidos_campos == null)
    manejoparametros.datos_leidos_campos = new java.util.Vector();
    // this.vector_datos =
    // manejoparametros.datos_leidos_tablas;
    // this.vector_datos_campos =
    // manejoparametros.datos_leidos_campos;
    this.campos = campos;
    this.vector_campos = vector_campos;
    this.map_campos = map_campos;
    // obtieneEncabezadoTabla();
    // asignaDatosCamposIniciales();
    // obtieneColumnasTabla();
    //public javax.swing.JTable iniciaTablaVector(
    public void iniciaTablaVector(
    boolean puede_editar,
    boolean puede_sortear,
    boolean puede_seleccionar)
    this.puede_editar = puede_editar;
    this.puede_sortear = puede_sortear;
    this.puede_seleccionar = puede_seleccionar;
    // Instead of making the table display the data as it would normally with:
    // JTable vista_tabla = new JTable(dataModel);
    // Add a sorter, by using the following three lines instead of the one above.
    //va TableSorter sorter = new TableSorter(dataModel);
    vista_tabla= new javax.swing.JTable();
    /*Desabilita el manejo de columna de la tabla para manejarlo manual*/
    vista_tabla.setAutoCreateColumnsFromModel(false);
    manejopantalla = new ManejoPantalla();
    obtieneColumnasTabla();
    this.vector_datos =
    manejoparametros.datos_leidos_tablas;
    this.vector_datos_campos =
    manejoparametros.datos_leidos_campos;
    iniciaVectorDatos();
    mimodelotabla = new miModeloTabla();
    /* mimodelotabla = new miModeloTabla(
    manejoparametros,
    vector_columnas,
    vector_datos,
    vector_datos_campos,
    campos,
    vector_campos,
    map_campos,
    manejopantalla);
    vista_tabla.setModel(mimodelotabla);
    configuraColumna(vista_tabla);
    asignaEscuchadores();
    // asignaAnchoColumnas(vista_tabla, mimodelotabla);
    // asignaEscuchadores();
    // Crear a modelo de tabla.
    class miModeloTabla extends javax.swing.table.AbstractTableModel
    java.util.Vector vector_columnas;
    java.util.Vector vector_campos_usar,
    vector_campos_usar_i;
    java.util.Vector vector_datos,vector_datos_campos;
    javax.swing.JComponent[] campos;
    java.util.Vector vector_campos;
    java.util.TreeMap map_campos;
    ManejoPantalla manejopantalla;
    ManejoParametros manejoparametros;
    public miModeloTabla(ManejoParametros manejoparametros,
    java.util.Vector vector_columnas,
    java.util.Vector vector_datos,
    java.util.Vector vector_datos_campos,
    javax.swing.JComponent[] campos,
    java.util.Vector vector_campos,
    java.util.TreeMap map_campos,
    ManejoPantalla manejopantalla)
    this.manejoparametros = manejoparametros;
    this.vector_columnas = vector_columnas;
    // this.vector_campos_usar = vector_campos_usar;
    // this.vector_campos_usar_i = vector_campos_usar_i;
    this.vector_datos = vector_datos;
    this.vector_datos_campos = vector_datos_campos;
    this.campos = campos;
    this.vector_campos = vector_campos;
    this.map_campos = map_campos;
    this.manejopantalla = manejopantalla;
    // javax.swing.table.TableModel dataModel =
    // new javax.swing.table.AbstractTableModel()
    // These methods always need to be implemented.
    /* Para asignar los anchos de la columna
    Se pueden asignar por el la columna que tenga mas tama�o
    public final Object[] valores_largo = {"Angela", "Andrews",
    "esto es mas que una prueba","prueba",
    "prueba","prueba","prueba","prueba","N"};*/
    class miModeloTabla extends javax.swing.table.AbstractTableModel
    public int getColumnCount()
    return vector_columnas.size();
    public int getRowCount()
    return vector_datos==null ? 0 : vector_datos.size();
    public Object getValueAt(int row, int col)
    int total_columna = ((java.util.Vector)
    (vector_datos.elementAt(row))).size() + 1;
    if (total_columna > col)
    return ((java.util.Vector)
    (vector_datos.elementAt(row))).elementAt(col);
    }else
    return null;
    // The default implementations of these methods in
    // AbstractTableModel would work, but we can refine them.
    public String getColumnName(int columna)
    String indice_str =(String)
    ((Object[])vector_columnas.elementAt(columna))[1];
    int indice_vector_campos = Integer.parseInt(indice_str);
    return (String)((Object[])
    vector_campos.elementAt(indice_vector_campos))[3];
    public Class getColumnClass(int columna)
    // {return getValueAt(0,columna).getClass();}
    String indice_str =(String)
    ((Object[])vector_columnas.elementAt(columna))[1];
    int indice_vector_campos = Integer.parseInt(indice_str);
    return (Class)obtieneTipoColumna(
    (String)((Object[])
    vector_campos.elementAt(indice_vector_campos))[29]);
    public boolean isCellEditable(int fila, int columna)
    if (puede_editar)
    String indice_str =(String)
    ((Object[])vector_columnas.elementAt(columna))[1];
    int indice_vector_campos = Integer.parseInt(indice_str);
    if (((String)
    ((Object[])
    vector_campos.elementAt(
    indice_vector_campos))[18]).equals("true"))
    return true;
    else
    return false;
    }else return false;
    /* public void setValueAt(Object aValue, int fila, int columna)
    if (puede_editar)
    ((java.util.Vector)
    (vector_datos.elementAt(fila))).elementAt(columna) = aValue;
    fireTableCellUpdated(fila, columna);
    // public static void main(String[] args) {
    // new TableExample3();
    //final de clase
    public void asignaDatosTabla(java.util.Vector vector_campos_usar,
    java.util.Vector vector_campos_usar_i,
    java.util.Vector vector_datos,
    java.util.Vector vector_datos_campos)
    this.vector_campos_usar = vector_campos_usar;
    this.vector_campos_usar_i = vector_campos_usar_i;
    this.vector_datos = vector_datos;
    this.vector_datos_campos = vector_datos_campos;
    // asignaDatosCamposIniciales();
    // mimodelotabla.fireTableDataChanged();
    // configuraColumna(vista_tabla);
    // javax.swing.table.TableModel modelo = vista_tabla.getModel();
    mimodelotabla.fireTableDataChanged();
    // vista_tabla.repaint();
    vista_tabla.requestFocus();
    javax.swing.ListSelectionModel listseleccion = vista_tabla.getSelectionModel();
    listseleccion.setLeadSelectionIndex(0);
    vista_tabla.setSelectionModel(listseleccion);
    //javax.swing.ListSelectionModel lsm =
    // (javax.swing.ListSelectionModel)e.getSource();
    // asignaEscuchadores();
    public void iniciaVectorDatos()
    java.util.Vector vectornulo;
    manejoparametros.datos_leidos_tablas.clear();
    if (!vector_columnas.isEmpty())
    for(int i=0;i<30;i++)
    vectornulo = new java.util.Vector();
    for (int j = 0;j<vector_columnas.size();j++)
    vectornulo.addElement(null);
    vector_datos.addElement(vectornulo);
    private void asignaEscuchadores()
    vista_tabla.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    if (puede_seleccionar) { // true by default
    modelo_fila_sel = vista_tabla.getSelectionModel();
    modelo_fila_sel.addListSelectionListener(
    new javax.swing.event.ListSelectionListener() {    
    public void valueChanged(
    javax.swing.event.ListSelectionEvent e)
    javax.swing.ListSelectionModel lsm =
    (javax.swing.ListSelectionModel)e.getSource();
    int fila_sel = lsm.getMinSelectionIndex();
    // DEBO BUSCAR UNA FORMA DE DETERMINAR SI EL VECTOR DE CAMPOS TIENE DATOS
    if (!vector_datos_campos.isEmpty())// !=null)
    manejopantalla.asignaDatosPantalla(
    (java.util.TreeMap)
    vector_datos_campos.elementAt(fila_sel),
    campos,
    vector_campos);
    /*Aqui funcionan para cambiar los campos de arriba de la forma
    que esta abajo
    ((javax.swing.JTextField)campos[0]).setText(
    (String)vista_tabla.getValueAt(fila_sel,0));
    ((javax.swing.JTextField)campos[1]).setText((String)vista_tabla.getValueAt(fila_sel,1));
    //v if (lsm.isSelectionEmpty()) {
    //v System.out.println("No rows are selected.");
    //v } else {
    //v int selectedRow = lsm.getMinSelectionIndex();
    //v System.out.println("Row " + selectedRow
    //v + " is now selected.");
    //v }
    } else {
    vista_tabla.setRowSelectionAllowed(false);
    vista_tabla.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent e) {
    fila_sel = vista_tabla.getSelectedRow();
    if (e.getClickCount() ==2)
    asignaDatosSeleccionados(fila_sel);
    salirPrograma();
    // System.out.println("FILA SEL --> " + fila_sel);
    /*Aqui va chequeo de seleccion
    ((javax.swing.JTextField)campos[0]).setText((String)vista_tabla.getValueAt(fila_sel,0));
    ((javax.swing.JTextField)campos[1]).setText((String)vista_tabla.getValueAt(fila_sel,1));
    vista_tabla.addKeyListener(new java.awt.event.KeyAdapter()
    public void keyPressed(java.awt.event.KeyEvent e)
    // char c = e.getKeyChar();
    int keycode = e.getKeyCode();
    if (keycode == 10)
    fila_sel = vista_tabla.getSelectedRow();
    asignaDatosSeleccionados(fila_sel);
    salirPrograma();
    // System.out.println("FILA SEL --> " + fila_sel);
    public void configuraColumna(javax.swing.JTable tabla)
    int tamano;
    for (int i=0;i<vector_columnas.size();i++)
    String indice_str =(String)
    ((Object[])vector_columnas.elementAt(i))[1];
    int indice_vector_campos = Integer.parseInt(indice_str);
    /*Aqui se asigna en render de cada celda esto permite
    fijar el font de las celdas, el borde, fijar, estado
    colores,etc. Debo crear uno propio para tener mas control*/
    javax.swing.table.DefaultTableCellRenderer
    renderer = new javax.swing.table.DefaultTableCellRenderer();
    /*Debo agregar un campo en el archivo de configuracion para
    saber como voy alinear el campo (derecha,izquierda,centro)*/
    renderer.setHorizontalAlignment(renderer.LEFT);
    //javax.swing.JLabel.LEFTNTER_ALIGNMENT);
    // renderer.setText((String)((Object[])
    // vector_campos.elementAt(
    // indice_vector_campos))[3]);
    if (!UtilitariosGenerales.isCampoBlanco(((String)((Object[])
    vector_campos.elementAt(
    indice_vector_campos))[26])))
    tamano = Integer.parseInt(((String)((Object[])
    vector_campos.elementAt(
    indice_vector_campos))[26]));
    }else
    tamano = 10;
    /*Debo crear mi propio tipo de editor de celdas, para formatear
    los datos debo llamarlo aqui, ahi tomo en cuenta el tipo de
    datos que voy a usar (JCombo, JcheckBox, JTextField)*/
    javax.swing.table.TableCellEditor editor;
    if (
    /* ((String)((Object[])
    vector_campos.elementAt(indice_vector_campos))[2]).equals("JCheckBox")
    ((String)((Object[])
    vector_campos.elementAt(indice_vector_campos))[29]).equals("Boolean")
    javax.swing.JCheckBox checkbox = new javax.swing.JCheckBox();
    editor = new javax.swing.DefaultCellEditor(checkbox);
    else
    javax.swing.JTextField jtextfield = new javax.swing.JTextField();
    editor = new javax.swing.DefaultCellEditor(jtextfield);
    javax.swing.table.TableColumn columna = new
    javax.swing.table.TableColumn(
    i,tamano,renderer,editor);
    tabla.addColumn(columna);
    public void obtieneColumnasTabla()
    vector_columnas = new java.util.Vector();
    int indice_vector;
    String[] informacion_columna;
    for (int i=0;i<vector_campos.size();i++)
    if (!
    ((String)((Object[])vector_campos.elementAt(i))[2]).equals(
    "JTable"))
    continue;
    informacion_columna = new String[2];
    informacion_columna[0] = (String)((Object[])vector_campos.elementAt(i))[3];
    informacion_columna[1] = String.valueOf(i);
    vector_columnas.addElement(informacion_columna);
    public Object obtieneTipoColumna(String tipo_columna)
    String[] arreglo_tipo = {"String","Long","Integer","Double","Boolean"};
    int i = java.util.Arrays.binarySearch(arreglo_tipo,tipo_columna);
    switch (i)
    case 0:
    return String.class;
    case 1:
    return Long.class;
    case 2:
    return Integer.class;
    case 3:
    return Double.class;
    case 4:
    return Boolean.class;
    default:
    return String.class;
    class FormattedCellRenderer extends javax.swing.table.DefaultTableCellRenderer
         protected java.text.Format m_format;
         public FormattedCellRenderer(java.text.Format format) {
              m_format = format;
         public java.awt.Component getTableCellRendererComponent(
    javax.swing.JTable table,
              Object value, boolean isSelected, boolean hasFocus,
              int nRow, int nCol)
              return super.getTableCellRendererComponent(table,
                   value==null ? null : m_format.format(value),
                   isSelected, hasFocus, nRow, nCol);
    class FormattedCellEditor extends javax.swing.DefaultCellEditor
         public FormattedCellEditor(final javax.swing.JFormattedTextField
                   formattedTextField) {
              super(formattedTextField);
    System.out.println(delegate);
              formattedTextField.removeActionListener(delegate);
              delegate = new EditorDelegate() {
                   public void setValue(Object value) {
                        formattedTextField.setValue(value);
                   public Object getCellEditorValue() {
                        return formattedTextField.getValue();
              formattedTextField.addActionListener(delegate);
              formattedTextField.setBorder(null);
    public void asignaDatosSeleccionados(int fila)
    if (fila >=0 && fila < vector_datos.size())
    manejoparametros.isSeleccionada = true;
    java.util.TreeMap map_datos_sel = new java.util.TreeMap();
    int indice_vector;
    int total_tabla=-1;
    int total_campos = -1;
    for (int i=0;i<vector_campos_usar.size();i++)
    // String[] arreglo_campo_usar = new String[2];
    // arreglo_campo_usar = (String[])vector_campos_usar.elementAt(i);
    // indice_vector = Integer.parseInt(arreglo_campo_usar[0]);
    /*AQUI DEBO CLASIFICAR SI ES FIJO O ES DE LA TABLA*/
    if (!
    ((String)((Object[])vector_campos_usar_i.elementAt(i))[2]).equals(
    "JTable"))
    if (!UtilitariosGenerales.isCampoBlanco(
    ((String)((Object[])vector_campos_usar_i.elementAt(i))[28]) ) &&
    !((String)((Object[])vector_campos_usar_i.elementAt(i))[40]).equals(
    "true"))
    if (!map_datos_sel.containsKey(
    ((Object[])vector_campos_usar_i.elementAt(i))[28]))
    total_campos++;
    Object valores = ((java.util.TreeMap)
    vector_datos_campos.elementAt(fila)).get(
    ((Object[])vector_campos_usar_i.elementAt(
    i))[28]);
    map_datos_sel.put( ((Object[])vector_campos_usar_i.elementAt(i))[28],
    valores);
    // ((java.util.Vector)
    // vector_datos_campos.elementAt(fila)).elementAt(total_campos) );
    // continue;
    for (int i =0;i<vector_campos.size();i++)
    if (
    ((String)((Object[])vector_campos.elementAt(i))[2]).equals(
    "JTable"))
    total_tabla++;
    if (!UtilitariosGenerales.isCampoBlanco(
    ((String)((Object[])vector_campos.elementAt(i))[28]) ))
    if (!map_datos_sel.containsKey(
    ((Object[])vector_campos.elementAt(i))[28]))
    map_datos_sel.put( ((Object[])vector_campos.elementAt(i))[28],
    ((java.util.Vector)
    vector_datos.elementAt(fila)).elementAt(i) );
    manejoparametros.fila_seleccionada = fila;
    manejoparametros.map_datos_seleccionados = map_datos_sel;
    public void obtieneDatosSeleccionados_ant(int fila)
    if (fila >=0 && fila < vector_datos.size())
    manejoparametros.isSeleccionada = true;
    java.util.TreeMap map_datos_sel = new java.util.TreeMap();
    int indice_vector;
    int total_tabla=-1;
    for (int i=0;i<vector_campos_usar.size();i++)
    // String[] arreglo_campo_usar = new String[2];
    // arreglo_campo_usar = (String[])vector_campos_usar.elementAt(i);
    // indice_vector = Integer.parseInt(arreglo_campo_usar[0]);
    /*AQUI DEBO CLASIFICAR SI ES FIJO O ES DE LA TABLA*/
    if (!
    ((String)((Object[])vector_campos_usar_i.elementAt(i))[2]).equals(
    "JTable"))
    continue;
    else
    total_tabla++;
    if (!UtilitariosGenerales.isCampoBlanco(
    ((String)((Object[])vector_campos_usar_i.elementAt(i))[28]) ))
    if (!map_datos_sel.containsKey(
    ((Object[])vector_campos_usar_i.elementAt(i))[28]))
    map_datos_sel.put( ((Object[])vector_campos_usar_i.elementAt(i))[28],
    ((java.util.Vector)
    vector_datos.elementAt(fila)).elementAt(total_tabla) );
    int total_campos = -1;
    for (int i=0;i<vector_campos.size();i++)
    if (!UtilitariosGenerales.isCampoBlanco(
    ((String)((Object[])vector_campos.elementAt(i))[28]) ) &&
    !((String)((Object[])vector_campos.elementAt(i))[2]).equals(
    "JEncadena"))
    if (!map_datos_sel.containsKey(
    ((Object[])vector_campos.elementAt(i))[28]))
    total_campos++;
    String valores = (String)((java.util.TreeMap)
    vector_datos_campos.elementAt(fila)).get(
    ((Object[])vector_campos.elementAt(
    i))[28]);
    map_datos_sel.put( ((Object[])vector_campos.elementAt(i))[28],
    valores);
    // ((java.util.Vector)
    // vector_datos_campos.elementAt(fila)).elementAt(total_campos) );
    manejoparametros.fila_seleccionada = fila;
    manejoparametros.map_datos_seleccionados = map_datos_sel;
    public void salirPrograma()
    try
    if (frame_usar instanceof javax.swing.JDialog)
    ((javax.swing.JDialog)frame_usar).setName("botones");
    ((javax.swing.JDialog)frame_usar).dispose();
    }else
    ((javax.swing.JFrame)frame_usar).setName("botones");
    ((javax.swing.JFrame)frame_usar).dispose();
    }catch (Exception ex)
    System.out.println(ex.toString());
    }

Maybe you are looking for

  • Reports are not drilled down.

    Hi All, I am working on CRM webclient reporting. I have the issue in Production system. In production system I am able to see alll the reports. Ex;- I want to see the Accounts all accounts I am able to see. But when I choose any account by clicking o

  • Macbook display problems

    Hi I have a macbook that was given the ol beer in the keyboard treatment and went dark with a ghost image, before I bought it, leading me to believe that it was the inverter board had blown, I bought one online and replaced it but to no avail. The pr

  • Unordered list bullets and Spry Accordion widget

    In all browsers except IE (surprise, surprise!), the page works fine. Otherwise the bullets in my unordered list appear at the bottom of the multiline text they are associated with. I haven't had this problem in similar pages not using the accordion

  • Read a text file from DB directly (don't use PLSQL).

    how can I Read a text file from DB directly (don't use PLSQL). ?

  • SDDM 3.1 PROD: Engineer to Relational creates too many new objects

    After upgrading to DM 3.1 production I am seeing many dublicates of my relational tables. It seems that when I perform "Engineer to Relational", some of the tables are recreated even though they already existed in the relational model. Currently, I h