Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 表格单元格上组件的ActionEvent不';不可能发生_Java_Swing_Lwuit_Tablemodel_Actionevent - Fatal编程技术网

Java 表格单元格上组件的ActionEvent不';不可能发生

Java 表格单元格上组件的ActionEvent不';不可能发生,java,swing,lwuit,tablemodel,actionevent,Java,Swing,Lwuit,Tablemodel,Actionevent,我的代码属于LWUIT应用程序,但LWUIT和JavaSwing之间存在一些共同的问题 我有一张桌子,它的最后一个单元格上有一个按钮,作为一个组件 我的问题很简单,为什么当我按下那个按钮时没有任何动作发生 我也试过checkbox,但我甚至不能做check Button b,b2; Object [][] elhind; b2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent

我的代码属于LWUIT应用程序,但LWUIT和JavaSwing之间存在一些共同的问题

我有一张桌子,它的最后一个单元格上有一个按钮,作为一个组件

我的问题很简单,为什么当我按下那个按钮时没有任何动作发生

我也试过checkbox,但我甚至不能做check

Button b,b2;

Object  [][] elhind;

b2.addActionListener(new ActionListener()
{
 public void actionPerformed(ActionEvent e)

 {
 elhind  = new  String[1][9];
 String elhind  [][] = {{"Netherlands","Germany","Austria","Romania","Bulgaria","England","Walse","Ireland","Belgium"}};

 Object ob  [][] = new  String[elhind.length][10];

 for(int col=0;col<9;col++) 
{

 for(int j=0;j<elhind.length;j++)
 {

  ob[j][col] = elhind[j][col];

 }
  }
  TableModel  model = new DefaultTableModel( new String[]{"col1","col2","col3","col4","col5","col6","col7","col8","col9","col10","col11"ob)   {
  public boolean isCellEditable(int row, int col)
 {
 return true;  
 }
 };

 elhind  = new  String[1][10];
 ob = new  String[1][10];

 Table  table = new Table(model,true);

 for(int col=0;col<10;col++)
 for(int j=0;j<1;j++)

 try
 {

 if(col ==8)
 {
  Button cb =new Button("lam");
 cb.setFocus(true);
 cb.addActionListener( new ActionListener()
 {
public void actionPerformed(ActionEvent acv)
{

System.out.print("Action done");
}
 });

 table.addComponent(cb);

}
 else 
 {
  model.setValueAt(j, col, elhind[j++][col++] )   ;
 }
 }
catch(java.lang.ArrayIndexOutOfBoundsException ee)
{
}
catch(java.lang.NullPointerException e3)
{
}
 }

}

);

您不应该向表中添加按钮,也不应该调用
setFocus()

可以将按钮作为单独的组件添加到公共父级,也可以重写tables createCell方法来为该情况生成按钮(前者更容易)


请使用requestFocus()而不是setFocus()。

请正确格式化您的代码您需要使用自定义的
CellEditor
JButton
,请看一看,您能为我解释一下这段代码吗,getActionCommand()不能在LUIT应用程序public void actionPerformed中使用(ActionEvent e){JTable table=(JTable)e、 getSource();int modelRow=Integer.valueOf(e.getActionCommand());((DefaultTableModel)table.getModel()).removeRow(modelRow);}渲染器负责在JTables视图中绘制,不要将JComponent放在XxxTableModel中,渲染组件只存储值、描述,这里多次Q&A,包括悬停效果,基本上所有内容都在oracle教程-如何使用中描述tables@mKorbel你是说我的想法完全错了吗?在table类上重写createCell方法并没有解决问题!请再看看我的线程,它怎么不工作了?你拿到密码了吗?这应该可以工作,但是你也应该检查行,因为这个方法也被用于标题单元格。
Table  table = new Table(model,true)
{     
protected Component createCell(Object value, final int row,
final int column, boolean editable) {
if (column == 0) {
try {
Button cod = new Button("cod");
cod.getStyle().setBgColor(0x00f0f0);
cod.addActionListener(new ActionListener()
 {
public void actionPerformed(ActionEventacv)                          
{      
System.out.print("hello LWuit");
} 
});
return cod;
}  
catch (Exception ex)
{
ex.printStackTrace();
}
 }
 return super.createCell(value, row, column, editable);
 }
 } ;