JTable中的一列是JComboBox,用TAB键移动到这一列时,如何让他变成JComboBox的样式? 大家好,请问:1,JTable中的一列是JComboBox,用TAB键移动到这一列时,如何让他变成JComboBox的样式?2,如何让这一列在初始表示的时候就表现成JComboBox的样式呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 加上renderer后,被选中的数据显示不出来。DEMO的例子没有这个效果的呀。 import java.awt.BorderLayout;import java.awt.Component;import javax.swing.*;import javax.swing.table.TableCellRenderer;public class T extends JComboBox implements TableCellRenderer{ public T() { setBorder(BorderFactory.createEmptyBorder()); } public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } JComboBox comboBox = new JComboBox(); comboBox.setBorder(BorderFactory.createEmptyBorder()); comboBox.addItem("Item-1"); comboBox.addItem("Item-2"); comboBox.addItem("Item-3"); comboBox.addItem("Item-4"); comboBox.addItem("Item-5"); DefaultCellEditor editor = new DefaultCellEditor(comboBox); JTable table = new JTable(5, 5); table.getColumnModel().getColumn(0).setCellRenderer(new T()); table.getColumnModel().getColumn(0).setCellEditor(editor); JScrollPane sp = new JScrollPane(table); JFrame f = new JFrame(); f.getContentPane().add(sp, BorderLayout.CENTER); f.pack(); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { this.removeAllItems(); this.addItem(value); return this; }} 再问:如果要使用ALT+向下键后打开下拉菜单,应该怎么实现呢? C:\j2sdk1.4.2_02\demo\jfc\SwingSet2\src\TableDemo.java 怎么在JPanel中添加一个背景图片,月简单越好 如何实现跨JVM应用?如何同一JVM实现多类装载器? 急! 排列的问题 java mail 软件打包问题 巨白痴问题,如何让jtextfield中的内容实时变化 setDividerLocation(double proportionalLocation) 好像不管用,真是急!! 如何在winme环境小设置jdk1。3。1的开发环境 JTextField 当文字激发事件 用actionEvent adjustmenEvent 都不行 :( 简单问题,50分,马上结账 大学生JAVA技术讨论群 关于JTable组件的问题??Help
DEMO的例子没有这个效果的呀。
import java.awt.Component;import javax.swing.*;
import javax.swing.table.TableCellRenderer;public class T extends JComboBox implements TableCellRenderer
{
public T()
{
setBorder(BorderFactory.createEmptyBorder());
}
public static void main(String[] args)
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
JComboBox comboBox = new JComboBox();
comboBox.setBorder(BorderFactory.createEmptyBorder());
comboBox.addItem("Item-1");
comboBox.addItem("Item-2");
comboBox.addItem("Item-3");
comboBox.addItem("Item-4");
comboBox.addItem("Item-5");
DefaultCellEditor editor = new DefaultCellEditor(comboBox);
JTable table = new JTable(5, 5);
table.getColumnModel().getColumn(0).setCellRenderer(new T());
table.getColumnModel().getColumn(0).setCellEditor(editor); JScrollPane sp = new JScrollPane(table);
JFrame f = new JFrame();
f.getContentPane().add(sp, BorderLayout.CENTER);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
} public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column)
{
this.removeAllItems();
this.addItem(value); return this;
}
}