DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: How to insert a list(radio button)inside a table cell?

  1. #1
    Join Date
    Nov 2006
    Posts
    5

    How to insert a list(radio button)inside a table cell?

    hi all...

    I'm building a java mobile application and i'm facing the problem of how to insert a list radio button inside a table cell where the table contains string value. Please help me in knowing the synatx ....

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    You should be able to do it ... tables are containers ... it's a matter of working it out with your TableModel. Take a look at the "How to use Tables" in the Java Tutorials (under "Creating a GUI with JFC/Swing", then "Using Swing Components")

  3. #3
    Join Date
    Nov 2006
    Posts
    5

    Mobile Applicatioin

    Does it matter with tables if i'm using the MIDlet inside of a simple java application?

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Since the MIDlet API is a subset of the full J2SE, I would deduce that it does not matter. I have not worked with the J2ME so I can't say that I've done what you're trying to do, but I expect that you can do it.

  5. #5
    Join Date
    Apr 2006
    Posts
    28
    May be this program give you some ideas about radio button

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    import javax.swing.table.TableModel;
    public class DisplayButtons extends JPanel
    {
    static JFrame myFrame;
    public DisplayButtons()
    {
    setLayout(new BorderLayout());
    JTable table=new JTable(new TableModel());
    JScrollPane pane=JTable.createScrollPaneForTable(table);
    add(pane);
    JComboBox comboBox=new JComboBox(new String[] {"Low","Medium","High"});
    TableColumn priorityColumn=table.getColumn("Priority");
    priorityColumn.setCellEditor(new DefaultCellEditor(comboBox));
    }
    public static void main(String args[])
    { myFrame =new JFrame("Exmaple ");
    DisplayButtons app=new DisplayButtons();
    myFrame.getContentPane().add("Center",app);
    myFrame.setSize(new Dimension(400,250));
    myFrame.addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    });
    myFrame.setVisible(true);
    }
    class TableModel extends AbstractTableModel
    {
    String [][] data={{"1","Java programming","H"},
    {"2","C# Programming","L"},
    {"3","C++ Programming","L"},
    {"4","Cobol Programming","L"},
    {"5","Fox Pro Programming","H"},
    {"6","Pascal Programming","L"},
    {"7","HTML ","L"},
    {"8","XML","L"},
    {"9","Java Script","L"},
    {"10","Visual Basic Programming","H"}
    };
    Boolean doneFlags[]={new Boolean(false),
    new Boolean(false),new Boolean(false),
    new Boolean(false),new Boolean(false),
    new Boolean(false),new Boolean(false),
    new Boolean(false),new Boolean(false),
    new Boolean(false)
    };
    String columnNames[]={"Course No","Course tilte","Priority","Done?"};
    public int getRowCount()
    {
    return data.length;
    }
    public int getColumnCount()
    {
    return columnNames.length;
    }
    public Object getValueAt(int row,int column)
    {
    if(column<3)
    return data[row][column];
    else
    return doneFlags[row];
    }
    public String getColumnName(int column)
    {
    return columnNames[column];

    }
    public void setValueAt(Object value,int row, int column)
    {
    if(value instanceof String)
    {
    data[row][column]=(String )value;
    }
    else if (value instanceof Boolean )
    {
    doneFlags[row]=(Boolean)value;
    }
    fireTableChanged(new TableModelEvent(this,row,row,column));

    }
    public boolean isCellEditable(int row,int col)
    {
    return true;
    }
    public Class getColumnClass(int c)
    {
    return getValueAt(0,c).getClass();
    }
    }
    }

  6. #6
    Join Date
    Nov 2006
    Posts
    5

    Is it MIDlet compatible?

    Thanks for ur effort...
    But i don't thinks that the code u send is for MIDlet (mobile application).
    I need the syntax for doing so in MIDlet.
    Please help me...
    Thanks

  7. #7
    Join Date
    Aug 2006
    Location
    STL, MO, USA
    Posts
    7
    Code:
    myFrame.addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    });
    Erm...Vanduc, you don't have to do that anymore...The more modern way is:
    Code:
    myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  8. #8
    Join Date
    Nov 2006
    Posts
    5

    MIDlet compatible code

    Hi...

    Actually i do know the code for inserting a radio button inside a table but what i need is how to insert the radio button ,which is the list in MIDlet, inside a table.
    Please help in the syntax....
    Thanks for all ur efforts.

  9. #9
    Join Date
    Jan 2008
    Location
    chennai
    Posts
    1
    Hi,
    I am also faceing the same problem pls help me to sort it otu
    With Regards
    Ganesan.N

  10. #10
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    There are a couple of situations going on in this over a year old thread.

    Which one are you plagued with?

Similar Threads

  1. Replies: 3
    Last Post: 06-24-2002, 11:42 PM
  2. SQL Tutorial (Answer Q's & post your reply)
    By bigbastard4 in forum Database
    Replies: 2
    Last Post: 05-16-2001, 06:24 PM
  3. Multi-row calculations
    By Bob Hines in forum Database
    Replies: 7
    Last Post: 04-27-2000, 11:14 AM
  4. Replies: 2
    Last Post: 04-13-2000, 01:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center