JList选中改变表现,JList的高度没有跟随改变。 本帖最后由 Willam2004 于 2010-03-01 13:53:05 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没人回答:可能是我问题描述的不清楚:我具体点:JLIst中,我自己写了ListCellRenderer的一个实现,他的getListCellRendererComponent方法,我返回了一个JPanel,上面有两个JLabel,默认时只显示一个JLabel,选中时全部显示,问题是,当我运行时,选中一个项时,该列表项的高度没有改变。不知道有没有知道该如何解决这个问题?public class MyCellRender extends JPanel implements ListCellRenderer { private JLabel contentLabel; private JLabel tipLabel; public MyCellRender(){ super(); contentLabel = new JLabel(); tipLabel = new JLabel(); this.setLayout(new BorderLayout()); this.add(contentLabel, BorderLayout.NORTH); this.add(tipLabel, BorderLayout.CENTER); } @Override protected void paintComponent(Graphics g) { // TODO Auto-generated method stub// super.paintComponent(g); } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { // TODO Auto-generated method stub String str = (String)value; contentLabel.setText(str); if(isSelected){ tipLabel.setText("ToolTip" + str); }else{ tipLabel.setText(""); } //设置背景选择颜色 ListRenderUtil.setColorForSelectionState(this, isSelected); //设置透明度 ListRenderUtil.opacify(this); return this; } } 一道线程题,发现没有答案,请问我这样选对吗? try-catch-finally 的输出顺序 native2ascii和记事本的保存编码设置的关系 初学者的绝对菜鸟问题,不菜你骂我。写作业着急 急急!!JAVA读取一个URL页面内容报500 100分,请教简单的问题,100分全给第一个答对的人 小问题!!! 数字转换成大写程序缺陷疑问 如何安装class包 我用JRUN3.0,但不能处理中文,该怎么办啊?请指教! 关于EDU.oswego.cs.dl.util.concurrent包中线程队列的问题 关于一条正则
我具体点:
JLIst中,我自己写了ListCellRenderer的一个实现,他的getListCellRendererComponent方法,我返回了一个JPanel,上面有两个JLabel,默认时只显示一个JLabel,选中时全部显示,问题是,当我运行时,选中一个项时,该列表项的高度没有改变。不知道有没有知道该如何解决这个问题?public class MyCellRender extends JPanel implements ListCellRenderer {
private JLabel contentLabel;
private JLabel tipLabel;
public MyCellRender(){
super();
contentLabel = new JLabel();
tipLabel = new JLabel();
this.setLayout(new BorderLayout());
this.add(contentLabel, BorderLayout.NORTH);
this.add(tipLabel, BorderLayout.CENTER);
} @Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
// super.paintComponent(g);
}
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
// TODO Auto-generated method stub
String str = (String)value;
contentLabel.setText(str);
if(isSelected){
tipLabel.setText("ToolTip" + str);
}else{
tipLabel.setText("");
}
//设置背景选择颜色
ListRenderUtil.setColorForSelectionState(this, isSelected);
//设置透明度
ListRenderUtil.opacify(this);
return this;
}
}