How do I make an Editable JCombobox within a Table Model?

Discussion in 'Java' started by KLD, Feb 15, 2004.

  1. KLD

    KLD Guest

    Within my table model , two of the columns contain a JComboBox dropdown of
    choices. I want to make one of the JComboBoxes editable, jcb_Status (so you
    can select from the dropdown, or type text in the field). I can only seem
    to get the first row in the table model to be editable, and then it does not
    put the drop down list on the subsequent items in the combobox.

    Winder_Table_Model _Winder_Table_Model = null;

    public void Display_Pattern_Table()
    {
    _Winder_Table_Model = new Winder_Table_Model();

    jtbl_Positions.setModel(_Winder_Table_Model);

    JComboBox jcb_Status = new JComboBox();
    // I tried this, it will only make the first item editable.
    // jcb_Status.setEditable(true);
    _DB_Roll_status_dcd.Populate_JComboBox(jcb_Status);

    // I thought maybe the setEditable only applied to the selected index and
    tried this.
    // It does not work either.
    // int i = jcb_Status.getItemCount();
    // for (int j=0 ; j < i-1 ; j++)
    // {
    // jcb_Status.setSelectedIndex(j);
    // jcb_Status.setEditable(true);
    // }

    jcb_Status.setSelectedIndex(0);

    JComboBox jcb_Defect = new JComboBox();
    _DB_Roll_reason_cd.Populate_JComboBox(jcb_Defect);
    jcb_Defect.setSelectedIndex(-1);

    jtbl_Positions.getColumnModel().getColumn(6).setCellEditor(new
    DefaultCellEditor(jcb_Status));
    jtbl_Positions.getColumnModel().getColumn(7).setCellEditor(new
    DefaultCellEditor(jcb_Defect));

    // Set up the notes column cell renderer
    jtbl_Positions.getColumnModel().getColumn(10).setCellRenderer(new
    Note_Cell_Renderer());

    // Don't allow multiple row selections

    jtbl_Positions.getSelectionModel().setSelectionMode(ListSelectionModel.SINGL
    E_SELECTION );

    jtbl_Positions.getTableHeader().setReorderingAllowed(false);
    jtbl_Positions.getTableHeader().setResizingAllowed(false);

    Winder_Table_Model.Set_Column_Widths(jtbl_Positions);
    }
     
    KLD, Feb 15, 2004
    #1
    1. Advertising

  2. KLD wrote:

    > Within my table model , two of the columns contain a JComboBox dropdown
    > of
    > choices. I want to make one of the JComboBoxes editable, jcb_Status (so
    > you
    > can select from the dropdown, or type text in the field). I can only seem
    > to get the first row in the table model to be editable, and then it does
    > not put the drop down list on the subsequent items in the combobox.
    >
    > Winder_Table_Model _Winder_Table_Model = null;
    >
    > public void Display_Pattern_Table()
    > {


    <snip ugly looking code>

    > _Winder_Table_Model = new Winder_Table_Model();
    > }


    Not really an answer to your problem, but I do have a suggestion:

    please use a better naming scheme for your code. Nobody writes code that
    looks like that in Java. As such, it is both a pain and harder to read your
    code, as it defies the naming conventions.
    All those underscores you use made me want to cry :)

    You can find the conventions here:
    http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

    Considering following the in the future, it makes it easier for everyone
    involved.

    --
    Kind regards,
    Christophe Vanfleteren
     
    Christophe Vanfleteren, Feb 15, 2004
    #2
    1. Advertising

  3. KLD

    KLD Guest

    "Christophe Vanfleteren" <> wrote in message
    news:0pBXb.1396$-ops.be...
    > KLD wrote:
    >
    > > Within my table model , two of the columns contain a JComboBox dropdown
    > > of
    > > choices. I want to make one of the JComboBoxes editable, jcb_Status (so
    > > you
    > > can select from the dropdown, or type text in the field). I can only

    seem
    > > to get the first row in the table model to be editable, and then it does
    > > not put the drop down list on the subsequent items in the combobox.
    > >
    > > Winder_Table_Model _Winder_Table_Model = null;
    > >
    > > public void Display_Pattern_Table()
    > > {

    >
    > <snip ugly looking code>
    >
    > > _Winder_Table_Model = new Winder_Table_Model();
    > > }

    >
    > Not really an answer to your problem, but I do have a suggestion:
    >
    > please use a better naming scheme for your code. Nobody writes code that
    > looks like that in Java. As such, it is both a pain and harder to read

    your
    > code, as it defies the naming conventions.
    > All those underscores you use made me want to cry :)
    >
    > You can find the conventions here:
    > http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
    >
    > Considering following the in the future, it makes it easier for everyone
    > involved.
    >
    > --
    > Kind regards,
    > Christophe Vanfleteren


    Please excuse my "ugly" naming conventions. I am a novice at this and am
    just trying to enhance someone elses existing code.
     
    KLD, Feb 15, 2004
    #3
  4. KLD

    Tony Morris Guest

    "KLD" <> wrote in message
    news:402ee698$0$49451$...
    > "Christophe Vanfleteren" <> wrote in message
    > news:0pBXb.1396$-ops.be...
    > > KLD wrote:
    > >
    > > > Within my table model , two of the columns contain a JComboBox

    dropdown
    > > > of
    > > > choices. I want to make one of the JComboBoxes editable, jcb_Status

    (so
    > > > you
    > > > can select from the dropdown, or type text in the field). I can only

    > seem
    > > > to get the first row in the table model to be editable, and then it

    does
    > > > not put the drop down list on the subsequent items in the combobox.
    > > >
    > > > Winder_Table_Model _Winder_Table_Model = null;
    > > >
    > > > public void Display_Pattern_Table()
    > > > {

    > >
    > > <snip ugly looking code>
    > >
    > > > _Winder_Table_Model = new Winder_Table_Model();
    > > > }

    > >
    > > Not really an answer to your problem, but I do have a suggestion:
    > >
    > > please use a better naming scheme for your code. Nobody writes code that
    > > looks like that in Java. As such, it is both a pain and harder to read

    > your
    > > code, as it defies the naming conventions.
    > > All those underscores you use made me want to cry :)
    > >
    > > You can find the conventions here:
    > > http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
    > >
    > > Considering following the in the future, it makes it easier for everyone
    > > involved.
    > >
    > > --
    > > Kind regards,
    > > Christophe Vanfleteren

    >
    > Please excuse my "ugly" naming conventions. I am a novice at this and am
    > just trying to enhance someone elses existing code.
    >
    >


    http://java.sun.com/docs/codeconv/

    --
    Tony Morris
    (BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
    Software Engineer
    IBM Australia - Tivoli Security Software
    (2003 VTR1000F)
     
    Tony Morris, Feb 15, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    Editable JComboBox

    Guest, Feb 16, 2005, in forum: Java
    Replies:
    0
    Views:
    508
    Guest
    Feb 16, 2005
  2. Jacques Chaurette

    using editable jcombobox

    Jacques Chaurette, Oct 2, 2005, in forum: Java
    Replies:
    7
    Views:
    5,901
    Ravindra Khyalia
    Sep 6, 2007
  3. Allen

    Editable JComboBox problems

    Allen, Oct 16, 2006, in forum: Java
    Replies:
    0
    Views:
    319
    Allen
    Oct 16, 2006
  4. @CL
    Replies:
    1
    Views:
    482
  5. Ben Phillips

    JComboBox: setting the editable text

    Ben Phillips, Oct 8, 2008, in forum: Java
    Replies:
    8
    Views:
    7,751
    Ben Phillips
    Oct 9, 2008
Loading...

Share This Page