Problem with JComboBox in aTable Cell

I try to put JComboBox in JTableCell,
what i want to do is something like this...
Question | Answer |
1. what is your favourite | a. Pizza |
food? | b. Hot Dog |
2. what is your favourite | a. red |
color? | b. blue |
Object[][] data = {
{"1.What is your favourite food?", new AnswerChoices(new String[]{"a.Pizza","b.Hot Dog"})},
{"2.What is your favourite color?", new AnswerChoices(new String[]{"a.red","b.blue"})}
here my code;
//class AnswerChoicesCellEditor
import javax.swing.table.*;
import javax.swing.*;
import java.awt.Component;
import java.awt.event.MouseEvent;
import java.util.EventObject;
import de.falcom.table.*;
public class AnswerChoicesCellEditor extends AbstractCellEditor implements TableCellEditor{
     protected JComboBox mComboBox;
public AnswerChoicesCellEditor(){
     mComboBox = new JComboBox();
     mComboBox.addActionListener(this);
     mComboBox.setEditable(false);
public Component getTableCellEditorComponent(JTable table,Object value,boolean isSelected,int row,int column){
     if(value instanceof AnswerChoices){
          AnswerChoices a = (AnswerChoices)value;
          String[] c = a.getChoices();
          mComboBox.removeAllItems();
          for(int i=0; i < c.length; i++)
               mComboBox.addItem(c);
               mComboBox.setSelectedIndex(a.getAnswer());
     return mComboBox;
public Object getCellEditorValue(){
     int nchoices = mComboBox.getItemCount();
     String[] c = new String[nchoices];
     for(int i = 0; i<nchoices; i++){
          c[i] = mComboBox.getItemAt(i).toString();
     return new AnswerChoices(c,mComboBox.getSelectedIndex());
     //return mComboBox.getSelectedItem(); //here i get but after selection there is no comboBox in tableCell
//the Renderer class
import javax.swing.table.TableCellRenderer;
import javax.swing.*;
import java.awt.Component;
public class AnswerChoicesCellRenderer extends JComboBox implements TableCellRenderer {
     private Object curValue;
/** Creates new AnswerChoiceCellRenderer */
public AnswerChoicesCellRenderer() {
setEditable(false);
public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column) {
if (value instanceof AnswerChoices) {
AnswerChoices nl = (AnswerChoices)value;
String[] tList = nl.getChoices();
if (tList != null) {
removeAllItems();
for (int i=0; i<tList.length; i++)
addItem(tList[i]);
     setSelectedIndex(AnswerChoices.getAnswer());
     //this.setSelectedItem();
//return this;
//this.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
if (table != null)
if (table.isCellEditable(row, column))
setForeground(CellRendererConstants.EDITABLE_COLOR);
else
setForeground(CellRendererConstants.UNEDITABLE_COLOR);
          setBackground(table.getBackground());
return this;
public class AnswerChoices {
     static int ans = 0;
     String[] choices ;
public AnswerChoices(String[]c,int a){
          choices = c;
          ans          = a;
public AnswerChoices(String[] c){
          this(c,0);
public String[] getChoices(){
     return choices;
public void setAnswer(int a){
     ans = a;
public static int getAnswer(){
     return ans;
//the TableModel i used in my app
import java.awt.Color;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import javax.swing.*;
public class FAL_Table extends JTable {
/** Creates new FAL_Table */
public FAL_Table(DefaultTableModel dtm) {
super(dtm);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
setRowSelectionAllowed(false);
setColumnSelectionAllowed(false);
setBackground(java.awt.Color.white);
setDefaultCellEditorRenderer();
private void setDefaultCellEditorRenderer(Class forClass, TableCellEditor editor, TableCellRenderer renderer) {
     setDefaultEditor(forClass, editor);
     setDefaultRenderer(forClass, renderer);
     private void setDefaultCellEditorRenderer() {
          // Setting default editor&renderer of Boolean
          setDefaultCellEditorRenderer(Boolean.class, new BooleanCellEditor(), new BooleanCellRenderer());
          //Setting default editor&renderer of ComboBox
          setDefaultCellEditorRenderer(JComboBox.class, new ComboBoxCellEditor( ),new ComboBoxRenderer());
          // Number class
          // Setting default editor&renderer of java.math.BigDecimal
          setDefaultCellEditorRenderer(java.math.BigDecimal.class,new NumberCellEditor(), new NumberCellRenderer());
          // Setting default editor&renderer of java.math.BigInteger
          setDefaultCellEditorRenderer(java.math.BigInteger.class,new NumberCellEditor(), new NumberCellRenderer());
          // Setting default editor&renderer of java.lang.Byte
          setDefaultCellEditorRenderer(Byte.class,new NumberCellEditor(), new NumberCellRenderer());
          // Setting default editor&renderer of Double
          setDefaultCellEditorRenderer(Double.class,new NumberCellEditor(), new NumberCellRenderer());
          // Setting default editor&renderer of Float
          setDefaultCellEditorRenderer(Float.class,new NumberCellEditor(), new NumberCellRenderer());
          // Setting default editor&renderer of Integer
          setDefaultCellEditorRenderer(Integer.class,new NumberCellEditor(), new NumberCellRenderer());
          // Setting default editor&renderer of Long
          setDefaultCellEditorRenderer(Long.class,new NumberCellEditor(), new NumberCellRenderer());
          // Setting default editor&renderer of Short
          setDefaultCellEditorRenderer(Short.class,new NumberCellEditor(), new NumberCellRenderer());
          // Setting default editor&renderer of String
          setDefaultCellEditorRenderer(String.class,new StringCellEditor(), new StringCellRenderer());
          // Setting default editor&renderer of FileName
          setDefaultCellEditorRenderer(FileName.class,new FileNameCellEditor(), new FileNameCellRenderer());
          // Setting default editor&renderer of Color
          setDefaultCellEditorRenderer(Color.class,new ColorCellEditor(), new ColorCellRenderer());
          setDefaultCellEditorRenderer(AnswerChoices.class, new AnswerChoicesCellEditor(), new AnswerChoicesCellRenderer());
          setDefaultCellEditorRenderer(JSpinner.class, new SpinnerCellEditor(), new SpinnerRenderer());
public Class getCellClass(int row,int col) {
TableModel model = getModel();
if (model instanceof FAL_TableModel) {
FAL_TableModel ptm = (FAL_TableModel)model;
return ptm.getCellClass(row,convertColumnIndexToModel(col));
return model.getColumnClass(convertColumnIndexToModel(col));
public TableCellRenderer getCellRenderer(int row, int column) {
TableColumn tableColumn = getColumnModel().getColumn(column);
TableCellRenderer renderer = tableColumn.getCellRenderer();
if (renderer == null) {
renderer = getDefaultRenderer(getCellClass(row,column));
return renderer;
public TableCellEditor getCellEditor(int row, int column) {
TableColumn tableColumn = getColumnModel().getColumn(column);
TableCellEditor editor = tableColumn.getCellEditor();
if (editor == null) {
editor = getDefaultEditor(getCellClass(row,column));
return editor;
import javax.swing.table.*;
import java.util.Vector;
import java.awt.event.MouseEvent;
import java.util.EventObject;
public class FAL_TableModel extends DefaultTableModel implements TableModel {
public FAL_TableModel() {
this((Vector)null, 0);
public FAL_TableModel(int numRows, int numColumns) {
super(numRows,numColumns);
public FAL_TableModel(Vector columnNames, int numRows) {
super(columnNames,numRows);
public FAL_TableModel(Object[] columnNames, int numRows) {
super(convertToVector(columnNames), numRows);
public FAL_TableModel(Vector data, Vector columnNames) {
setDataVector(data, columnNames);
public FAL_TableModel(Object[][] data, Object[] columnNames) {
setDataVector(data, columnNames);
     public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
Object obj = getValueAt(row,col);
if (col != 1){
return false;
     }else{
          return true;
public Class getCellClass(int row,int col) {
Object obj = getValueAt(row,col);
if (obj != null)
     return obj.getClass();
     else
     return Object.class;
public Object getCellValue(int row,int col) {
Object obj = getValueAt(row,col);
          return obj;      
my problem is, when i select an item from one of the comboBox in the table the value of the other cells changes too and i have the same problem with JSpinner.
please help i am stuck
Gebi

and when i try to get the current value oa a cell it returns the Component class like this
AnswerChoices@bf1f20 ...

Similar Messages

  • FocusListener problem with JComboBox

    Hi,
    I am facing a problem with JComboBox. When I make it as Editable it is not Listening to the FocucListener Event....
    Please tell me if there is any way to overcome this..
    Regards,
    Chandan Sharma

    I searched the forum using "jcombobox focuslistener editable" and quess what, the first posting I read had the solution.
    Search the forum before posting questions.

  • Strange problem with JComboBox

    I am having a strange problem with JComboBox, I created a method as a JComboBox factory which returns a JComboBox filled with items. the method works fine and I can see the items in the JComboBox. The problem is when I try using the method myCombo.SelectedItem(String item); the object myCombo does not set the selected item, it just leaves the item blank (or unselected).
    //This method build a JComboBox
    public javax.swing.JComboBox makeJComboBox(String[] items) {
    javax.swing.JComboBox myComboBox = new javax.swing.JComboBox();
    for (int index=0;index<items.length;index++){
    myComboBox.addItem(makeObj(items[index]));
    return myComboBox;
    public Object makeObj(final String item) {
    return new Object() {
    public String toString() {
    return item;
    }

    Couple of better ways to populate a combo with items-
    public javax.swing.JComboBox makeJComboBox(String[]items) {
    javax.swing.ComboBoxModel cbModel = new DefaultComboBoxModel(items);
    javax.swing.JComboBox myComboBox = new javax.swing.JComboBox(cbModel);
    return myComboBox;
    }OR
    public javax.swing.JComboBox makeJComboBox(String[]items) {
    return new javax.swing.JComboBox(items);

  • Problem with addRow and MultiLine Cell renderer

    Hi ,
    Ive a problem with no solution to me .......
    Ive seen in the forum and Ivent found an answer.......
    The problem is this:
    Ive a JTable with a custom model and I use a custom multiline cell renderer.
    (becuse in the real application "way" hasnt static lenght)
    When I add the first row all seem to be ok.....
    when I try to add more row I obtain :
    java.lang.ArrayIndexOutOfBoundsException: 1
    at javax.swing.SizeSequence.insertEntries(SizeSequence.java:332)
    at javax.swing.JTable.tableRowsInserted(JTable.java:2926)
    at javax.swing.JTable.tableChanged(JTable.java:2858)
    at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableMo
    del.java:280)
    at javax.swing.table.AbstractTableModel.fireTableRowsInserted(AbstractTa
    bleModel.java:215)
    at TableDemo$MyTableModel.addRow(TableDemo.java:103)
    at TableDemo$2.actionPerformed(TableDemo.java:256)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
    64)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
    ctButton.java:1817)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
    .java:419)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
    istener.java:245)
    at java.awt.Component.processMouseEvent(Component.java:5134)
    at java.awt.Component.processEvent(Component.java:4931)
    at java.awt.Container.processEvent(Container.java:1566)
    at java.awt.Component.dispatchEventImpl(Component.java:3639)
    at java.awt.Container.dispatchEventImpl(Container.java:1623)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
    at java.awt.Container.dispatchEventImpl(Container.java:1609)
    at java.awt.Window.dispatchEventImpl(Window.java:1590)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:197)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    This seems to be caused by
    table.setRowHeight(row,(getPreferredSize().height+2)); (line 164 of my example code)
    About the model I think its ok.....but who knows :-(......
    Please HELP me in anyway!!!
    Example code :
    import javax.swing.*;
    import javax.swing.table.*;
    import java.text.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class TableDemo extends JFrame {
    private boolean DEBUG = true;
    MyTableModel myModel = new MyTableModel();
    MyTable table = new MyTable(myModel);
    int i=0;
    public TableDemo() {
    super("TableDemo");
    JButton bottone = new JButton("Aggiungi 1 elemento");
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    //table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    //Add the scroll pane to this window.
    getContentPane().add(bottone,BorderLayout.NORTH);
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    bottone.addActionListener(Add_Action);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    class MyTable extends JTable {
    MultiLineCellRenderer multiRenderer=new MultiLineCellRenderer();
    MyTable(TableModel tm)
    super(tm);
    public TableCellRenderer getCellRenderer(int row,int col) {
              if (col==1) return multiRenderer;
              else return super.getCellRenderer(row,col);
    class MyTableModel extends AbstractTableModel {
    Vector data=new Vector();
    final String[] columnNames = {"Name",
    "Way",
    "DeadLine (ms)"
    public int getColumnCount() { return 3; }
    public int getRowCount() { return data.size(); }
    public Object getValueAt(int row, int col) {
    Vector rowdata=(Vector)data.get(row);
                                                                return rowdata.get(col); }
    public String getColumnName(int col) {
    return columnNames[col];
    public void setValueAt (Object value, int row,int col)
         //setto i dati della modifica
    Vector actrow=(Vector)data.get(row);
    actrow.set(col,value);
         this.fireTableCellUpdated(row,col);
         public Class getColumnClass(int c)
              return this.getValueAt(0,c).getClass();
         public boolean isCellEditable(int row, int col) {
    //Note that the data/cell address is constant,
    //no matter where the cell appears onscreen.
    if (col == 1)
    return false;
    else
    return true;
    public void addRow (String name,ArrayList path,Double dead) {
         Vector row =new Vector();
         row.add(name);
         row.add(path);
         row.add(dead);
         row.add(name); //!!!Mi tengo questo dato da utilizzare come key per andare a
         //prendere il path nella lista dei paths di Project
         //(needed as key to retrive data if name in col. 1 is changed)
         data.add(row);
         //Inspector.inspect(this);
         System.out.println ("Before firing Adding row...."+this.getRowCount());
         this.fireTableRowsInserted(this.getRowCount(),this.getRowCount());
    public void delRow (String namekey)
    for (int i=0;i<this.getRowCount();i++)
    if (namekey.equals(this.getValueAt(i,3)))
    data.remove(i);
    this.fireTableRowsDeleted(i,i);
    //per uscire dal ciclo
    i=this.getRowCount();
    public void delAllRows()
    int i;
    int bound =this.getRowCount();     
    for (i=0;i<bound;i++)     
         {data.remove(0);
         System.out.println ("Deleting .."+data);
    this.fireTableRowsDeleted(0,i);          
    class MultiLineCellRenderer extends JTextArea implements TableCellRenderer {
    private Hashtable rowHeights=new Hashtable();
    public MultiLineCellRenderer() {
    setEditable(false);
    setLineWrap(true);
    setWrapStyleWord(true);
    //this.setBorder(new Border(
    public Component getTableCellRendererComponent(JTable table,Object value,                              boolean isSelected, boolean hasFocus, int row, int column) {
    //System.out.println ("Renderer called"+value.getClass());
    if (value instanceof ArrayList) {
    String way=new String     (value.toString());
    setText(way);
    TableColumn thiscol=table.getColumn("Way");
    //System.out.println ("thiscol :"+thiscol.getPreferredWidth());
    //setto il size della JTextarea sulle dimensioni della colonna
    //per quanto riguarda il widht e su quelle ottenute da screen per l'height
    this.setSize(thiscol.getPreferredWidth(),this.getPreferredSize().height);
    // set the table's row height, if necessary
    //System.out.println ("Valore getPreferred.height"+getPreferredSize().height);
         if (table.getRowHeight(row)!=(this.getPreferredSize().height+2))
         {System.out.println ("Setting Row :"+row);
             System.out.println ("Dimension"+(getPreferredSize().height+2));
             System.out.println ("There are "+table.getRowCount()+"rows in the table ");
             if (row<table.getRowCount())
             table.setRowHeight(row,(getPreferredSize().height+2));
    else
    setText("");
    return this;
    /**Custom JTextField Subclass che permette all'utente di immettere solo numeri
    class WholeNumberField extends JTextField {
    private Toolkit toolkit;
    private NumberFormat integerFormatter;
    public WholeNumberField(int value, int columns) {
    super(columns);
    toolkit = Toolkit.getDefaultToolkit();
    integerFormatter = NumberFormat.getNumberInstance(Locale.US);
    integerFormatter.setParseIntegerOnly(true);
    setValue(value);
    public int getValue() {
    int retVal = 0;
    try {
    retVal = integerFormatter.parse(getText()).intValue();
    } catch (ParseException e) {
    // This should never happen because insertString allows
    // only properly formatted data to get in the field.
    toolkit.beep();
    return retVal;
    public void setValue(int value) {
    setText(integerFormatter.format(value));
    protected Document createDefaultModel() {
    return new WholeNumberDocument();
    protected class WholeNumberDocument extends PlainDocument {
    public void insertString(int offs,
    String str,
    AttributeSet a)
    throws BadLocationException {
    char[] source = str.toCharArray();
    char[] result = new char[source.length];
    int j = 0;
    for (int i = 0; i < result.length; i++) {
    if (Character.isDigit(source))
    result[j++] = source[i];
    else {
    toolkit.beep();
    System.err.println("insertString: " + source[i]);
    super.insertString(offs, new String(result, 0, j), a);
    ActionListener Add_Action = new ActionListener() {
              public void actionPerformed (ActionEvent e)
              System.out.println ("Adding");
              ArrayList way =new ArrayList();
              way.add(new String("Uno"));
              way.add(new String("Due"));
              way.add(new String("Tre"));
              way.add(new String("Quattro"));
              myModel.addRow(new String("Nome"+i++),way,new Double(0));     
    public static void main(String[] args) {
    TableDemo frame = new TableDemo();
    frame.pack();
    frame.setVisible(true);

    In the addRow method, change the line
    this.fireTableRowsInserted(this.getRowCount(),this.getRowCount()); to
    this.fireTableRowsInserted(data.size() - 1, data.size() - 1);Sai Pullabhotla

  • Problem with JComboBox in a fixed JToolBar

    Hi,
    I've created a JComboBox in a JToolBar that contains all available fonts. When I click on the drop down arrow I only see the first font and a small part of the second. The JComboBox is dropped down in fact just as far as the border of the JToolbar. All the rest isn't visible to me; it seems that they are behind the other components of my JApplet. However, if I move the JToolBar from it's position (as it's a floatable component), there's no problem at all. So I'm wondering why I can't see everything when the JToolBar is docked.... Can anyone help me?
    Thanks in advance!!
    E_J

    it seems that they are behind the other components of my JApplet.Sounds like you are mixing AWT components with your Swing application. Make sure you are using JPanel, JButton ... and not Panel, Button....

  • Problem with CheckBox as table cell renderer

    i m making a JTable having three columns.
    i m also making a cellRenderer of my own MyRenderer
    extending Jcheckbox and implementing TableCellRenderer
    now i m setting MyRenderer as renderer for third column in my table and
    DefaultCellEditor with jcheckbox as parameter as cell editor for this column
    the code is like this--------------------
    ****making of JTable****
    table= new JTable(3,3);
    JScrollPane scrollPane = new JScrollPane(table);
    TableColumn tableColumn = table.getColumn("Male"); // let us suppose that this gives third column
    tableColumn.setCellRenderer(new MyRenderer ());
    tableColumn.setCellEditor(new DefaultCellEditor(new JCheckBox()));
    *****The classs implementing TableCellRenderer is given below******
    class MyRenderer extends JCheckBox implements TableCellRenderer{
    public MyRenderer(){
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column){
    if(value != null){
    Boolean booleanValue = (Boolean)value;
    setSelected(booleanValue.booleanValue());
    return this;
    ***********************************Problem****************************
    The problem is that when we click on the cell of that column first time,
    all the cells are selected.
    I don't want to use getColumnClass() method for this problem .
    If possible , please give some other solution.
    what is the problem behind this,If anybody can help us.
    Thanks in advance.

    I think the problem is, when the value is null the checkbox return with the selected state, b'coz u r
    returning the checkbox (as it is). so pl'z try with below code (ADDED).
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column){
    if(value != null){
    Boolean booleanValue = (Boolean)value;
    setSelected(booleanValue.booleanValue());
    else /// ADDED
    setSelected(false);/// ADDED
    return this;
    Nediaph.

  • Excel cells appear garbled; either multiple values in single field or problem with redrawing of the cells.

    In editing a simple, new Excel 2013 file, I am seeing certain cells with multiple, overlapping values in the a single cell.  This is in the A-column so, not a matter of margins.  Specificially, in one cell, I had "Design", then replaced
    that text with "Reqt".  Now I see the word "Reqt" written over "Design".  when trying to delete the values, I can remove the "Reqt" value, but the "Design" value will not disappear/delete.
    I've tried saving and reopenning the file with no effect; problem persists.  Makes me think this is a corrupted .xlsx file, even though I just started from scratch 15 minutes before the problem arose.
    I appreciate any guidance (or bug submission) you can support.
    V/R,
    Kevin

    I have successfully inserted seven records in one form submit operation by looping through the command object execute method.
    However, the data that is being inserted by the command object is repetition of the first record and the command object is not taking any data from the text boxes for the second record onwards. In this I had used the isert record behavious generated by DW CS4 and modified it to suit my requirement. However, the data inserted in the first row is getting repeated in all the seven rows.
    Please help.
    Also advise if there are any free dreamweaver server side validation extensions available.

  • Event problem with JComboBox

    Hi, javamen.
    I ve gotten a little problem when working with Itemlistener interface. My combo has 4 options, in which the first one always appears when the applet starts up. Whenever the user DOESNT change it and submit the applet form, throught a button click, the applet gets a NullPointerException. But, if the user changes the option, i always get it, throught my interface' methods(ItemStateChanged). Of course, i know its because there was no combobox event, just a button event (click). So, how can i deal with this situation, since i need to get the combobox option content.
    Regards, Euclides.

    But, this is the question! I dont know how to initialize the combobox' first option. Help me, please! I am using the addItem method as follow:
    MakeJCombo ( JComboBox ComboObj) {
    ComboObj.addItem ("option1");
    ComboObj.addItem ("option2");
    ComboObj.addItem ("option3");
    then:
    public void itemStateChange(ItemEvent ie) ...
    Object origem = ie.getSource()...
    if (origem == ComboObj) ...

  • Problem with JComboBox in a JPanel

    I have a JComboBox in a JPanel (with a gridbaglayout), and I add items to the combobox:
    String[] stateList={"AL",.....};
    JCombobox stateCB=new JComboBox(stateList);
    and when I run the application, the states appear in the box, but when I click on the box, there is no drop-down list!
    any ideas?

    Is the combobox Enabled if it is then after adding it to anything set it to true cause i poersonally tried out as u have given it it works and else if it does not show a list then use the setmodel function and set the model to DefaultComboBoxModel and then add the items using a for loop

  • Problem with JComboBox in j2sdk 1.4.2_01

    Hi,
    I've got a JComboBox, and I want to change its background color. I use this code:
    BasicComboBoxEditor editor = (BasicComboBoxEditor)myJComboBox.getEditor();
    editor.getEditorComponent().setBackground(SystemColor.control);
    This code works with versions 1.3.1 and 1.4.1, but with version 1.4.2_01 it doesn't.
    Can anyone tell me another way to change the background color??
    Thanx in advance.

    Hi,
    I've got a JComboBox, and I want to change its background color. I use this code:
    BasicComboBoxEditor editor = (BasicComboBoxEditor)myJComboBox.getEditor();
    editor.getEditorComponent().setBackground(SystemColor.control);
    This code works with versions 1.3.1 and 1.4.1, but with version 1.4.2_01 it doesn't.
    Can anyone tell me another way to change the background color??
    Thanx in advance.

  • The problem with JComboBox

    hi,
    i have a JComboBox that has 3 items, when user choose one of them,
    how can i get it as a string to store into database.
    thanks a lot..

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class test extends JFrame implements ItemListener {
      JComboBox comboBox;
      public test() {
        super("JComboBox");
        String[] comboBoxItems = {
          "one", "two", "three"
        comboBox = new JComboBox(comboBoxItems);
        comboBox.addItemListener(this);
        JPanel panel = new JPanel();
        panel.add(new JLabel("select one"));
        panel.add(comboBox);
        getContentPane().add(panel, BorderLayout.CENTER);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(200,100);
        setLocationRelativeTo(null);
        setVisible(true);
      public void itemStateChanged(ItemEvent e) {
        if(e.getStateChange() == ItemEvent.SELECTED) {
          String selection = (String)e.getItem();
          System.out.println("selection = " + selection);
      public static void main(String[] args) {
        new test();
    }

  • Problem with setCursor for JButton in cell on JTable

    i have a problem with setCursor to JButton that is in a cell of the JTable}
    this is the code
    public class JButtonCellRenderer extends JButton implements TableCellRenderer {
    public JButtonCellRenderer() {
    setOpaque(true);
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column) {
    if (isSelected) {
    setForeground(table.getSelectionForeground());
    setBackground(table.getSelectionBackground());
    else {
    setForeground(table.getForeground());
    setBackground(Color.WHITE);
    setBorder(null);
    if(table.getValueAt(row,column) == null){
    setText("");
    if(isSelected){
    setBackground(table.getSelectionBackground());
    }else{
    setBackground(Color.WHITE);
    }else{
    if(table.getValueAt(row,column) instanceof JButton){
    JButton _button = (JButton)table.getValueAt(row,column);
    if(_button.getText().trim().equals("")){
    setText("<html>"+ "<font size=\"3\" COLOR=\"#0000FF\"><u><b>Ver...</b></u></font>"+"");
    }else{
    setText("<html>"+ "<font size=\"3\" COLOR=\"#0000FF\"><u><b>" + _button.getText() + "</b></u></font>"+"");
    return this;
    }

    Not quite sure I understand the problem, but I guess you have tried to call setCursor on your renderer and found it didn't work? The reason, I think, is that the renderer only renders a JButton. The thing that ends up in the table is in fact only a "picture" of a JButton, and among other things it won't receive and interact with any events, such as MouseEvents (so it wouldn't know that the cursor should change).
    There are at least two alternatives for you: You can perhaps use a CellEditor instead of a CellRenderer. Or you can add a MouseListener to the table and then use the methods column/rowAtPoint to figure out if the cursor is over your JButton cell and change the cursor yourself if it is.

  • Problem with 'Word edit cell.vi' , Inputs transduced with the value of every row repeated

    Hello,
    Im using LV2013 with office 2013 report tool kit. I am trying to use Word edit cell to input values in table previously created in template .doc.
    Indeed, i trying the example Generate report from template and didnt works well. I search for solution and I see it was a problem with previous version but it seems not solve totally in this version for word office 2010. 
    http://digital.ni.com/public.nsf/allkb/4041ECB5D02BA57D862579A00002FE8D
    I checked this thread but i didnt get it to works. http://forums.ni.com/t5/LabVIEW/Problem-with-append-table-and-Word-2010/m-p/2190960#M702610
    Any way to solve it?.
    Thanks for help.
    Fred
    Attachments:
    error.png ‏32 KB
    Untitled 1.vi ‏19 KB
    exampleTemplate.doc ‏37 KB

    Hello, I solve it adding this to Word_insert_Table.
    http://forums.ni.com/t5/LabVIEW/Report-Generation-MS-Word-Table-Bug/td-p/1605170
    Thanks.
    Open [LabVIEW installation folder]\vi.lib\addons\_office\_wordsub.llb\Word_Insert_Table.vi
    There is a nested for loop that interprets the provided string array data and reformats it into a long ASCII string for the copy buffer. It should look like this:
    Change the nested loop to look like this:
    The changes I've made are twofold:
    1. Within the inner loop, replace the "\n" char with a Tab character
    2. Just after the inner loop, add a new "concatenate strings" function that adds "\n".

  • Problem with Cell size in Excel output of XML report

    Dear all,
    I am facing a problem with cell size when i run my XML report in Excel output. I found that it imitates the cell size of whatever i gave in the RTF. I cannot increase the cell size in RTF as my report contains 60 columns and max width of MS Word table is 22 inches.
    Can any one suggest a way of doing this which shows full data in Excel sheet depending on the column data size with out any word wrap.
    Thanks
    RAJ

    Hi ,
    You can try with
    <xsl:attribute xdofo:ctx="block" name="wrap-option">no-wrap</xsl:attribute>
    may be helpful to you
    Thanks,
    Ananth
    http://bintelligencegroup.wordpress.com/

  • Printing problem with gray cells in smartforms

    Hi there,
    i have developed a smart form with some color logo and some gray shaded cells. If i print it by SAPLPD it comes out fine but when i print it on a printer configured in SAP it doesn’t come out properly. All the gray cells print as black cells. Any advice?
    Regards.

    Asif,
    it some times depends upon the printer drivers also
    i faced the same problem with one printer then i tried with the other hpcolor printer then i got the printout perfectly that means sometimes the drivers of the printer will crash with the program
    so its better u try this one in the another printer
    if u have this problem futher let me know
    Regards
    naveen

Maybe you are looking for