资源简介
JTable 在一个单元格放入多个按钮,
代码片段和文件信息
package TableButton;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
public class MyButtonEditor extends AbstractCellEditor implements
TableCellEditor
{
/**
* serialVersionUID
*/
private static final long serialVersionUID = -6546334664166791132L;
private JPanel panel;
private JButton button;
private JButton button1;
private ArrayList btnName;
public MyButtonEditor()
{
initButton();
initPanel();
panel.add(button);
panel.add(button1);
}
private void initButton()
{
button = new JButton();
button1 = new JButton();
button.setSize(new Dimension(50 25));
button1.setSize(new Dimension(50 25));
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int res = JOptionPane.showConfirmDialog(null
“我是“+button.getName() “choose one“
JOptionPane.YES_NO_OPTION);
if (res == JOptionPane.YES_OPTION)
{
//num++;
}
// stopped!!!!
fireEditingStopped();
}
});
button1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int res = JOptionPane.showConfirmDialog(null
“我是李四“ “choose one“
JOptionPane.YES_NO_OPTION);
if (res == JOptionPane.YES_OPTION)
{
//num++;
}
// stopped!!!!
fireEditingStopped();
}
});
}
private void initPanel()
{
panel = new JPanel();
panel.setLayout(new FlowLayout());
}
@Override
public Component getTableCellEditorComponent(JTable table object value
boolean isSelected int row int column)
{
btnName = (ArrayList) value;
button.setText(value == null ? ““ : btnName.get(0));
button1.setText(value == null ? ““ : btnName.get(1));
return panel;
}
@Override
public object getCellEditorValue()
{
return btnName;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2363 2015-08-12 06:31 TableButton\MyButtonEditor.java
文件 1359 2015-08-12 06:28 TableButton\MyButtonRenderer.java
文件 3177 2015-08-12 06:29 TableButton\TestTable.java
目录 0 2015-08-12 06:33 TableButton
----------- --------- ---------- ----- ----
6899 4
- 上一篇:超声波测距通过串口发送
- 下一篇:Processing
评论
共有 条评论