2013年9月8日星期日

JTABLE which put JLABEL add mouse events show slower border issues

Beginner JAVA, doing a picture browser when encountered a problem

JTtable do I want to use thumbnails , and then reload the DefaultTableCellRenderer of getTableCellRendererComponent method, the return value into a Jlabel

Then I had a mouse in JTtable Riga events for the selected cell LABEL add a border , but the display is very slow, or the window is minimized and then restored after the border to appear. and then I just setborder statement followed by a one JOptionPane, display to normal. Well, I think it should not be blocked ah what the relationship should be the component's display rendering problems .
I tried to add validate and updateComponentTreeUI, but will not work, it is to ask what it is , how to solve , experts advise.

key code as follows :


//thumbnailTable自定义的JTable
thumbnailTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int row=thumbnailTable.getSelectedRow();
int column=thumbnailTable.getSelectedColumn();
if (selectedLabel!=null) {
……
}
selectedLabel=(JLabel)thumbnailTable.getValueAt(row, column);
selectedLabel.setBorder(new LineBorder(Color.GRAY));
……
}
});

------ Solution ------------------------------------- -------
  This reply was moderator deleted at 2010-12-21 14:44:08

------ For reference only ---------------------------------- -----
  The reply on 2010-12-20 10:22:29 deleted by moderator

------ For reference only ---------------------------------- -----
die ............ still can not solve ==
Continue to top ............
I want not just to change but I'm too lazy to rewrite ideas ............ ==
I mainly overloaded DefaultTableCellRenderer of getTableCellRendererComponent method, the effect of the selected cell is gone, I do not know how to write , so I had this effect on added JLABEL .

Can anyone tell me why this effect has to be written ?

Now my custom JTABLE code is as follows :


public class Ex02aJTable extends JTable {
private static final long serialVersionUID=20101215L;
public Ex02aJTable(int numRows,int numColumns) {
super(numRows,numColumns);
init();
}
private void init() {
this.setRowHeight(0, 60);
TableColumnModel columnModel=this.getColumnModel();
Enumeration<TableColumn> columns=columnModel.getColumns();
while (columns.hasMoreElements()) {
columns.nextElement().setPreferredWidth(70);
}
this.setShowGrid(false);
this.setIntercellSpacing(new Dimension(10,0));
this.setBackground(new Color(0Xeeeeee));
}
public TableCellRenderer getDefaultRenderer(Class<?> columnClass) {
ImageRenderer renderer=new ImageRenderer();
return renderer;
}
public boolean isCellEditable(int row,int column) {
return false;
}
private class ImageRenderer extends DefaultTableCellRenderer {
public static final long serialVersionUID=20101216L;
public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column) {
if (isSelected) {
……//这样吗????不会啊啊啊啊啊啊
}
return (JLabel)value;
}
}

------ For reference only ----------------------------------- ----
solved ==
I steadfastly added SwingUtilities.updateComponentTreeUI (thumbnailTable); actually solved ==

This is God Ma , I had misjudged you ?

saying that in fact, I still do not understand , SwingUtilities.updateComponentTreeUI (thumbnailTable); This in the end is doing God horse . . . . . Who will explain the way to send points Score

rewrite code :


//thumbnailTable是放LABEL的表格,表格第一行是缩略图,第二行是图片名称
//column是选中的列
private void setSelectionFace(int column) {
if (selectedImg!=null && selectedName!=null) {
selectedImg.setBorder(null);
selectedImg.setOpaque(false);
selectedName.setOpaque(false);
}
selectedImg=(JLabel)thumbnailTable.getValueAt(0, column);
selectedImg.setBorder(new LineBorder(Color.GRAY));
selectedImg.setOpaque(true);
selectedImg.setBackground(Color.WHITE);
selectedName=(JLabel)thumbnailTable.getValueAt(1, column);
selectedName.setOpaque(true);
selectedName.setBackground(Color.WHITE);
SwingUtilities.updateComponentTreeUI(thumbnailTable);//这个到底什么用的?为什么加了就解决了……我以前每次遇到这种显示问题就加validate或者这个,其实我不是很明白到底啥用的
}

------ For reference only ----------------------------------- ----
this look java tutorial swing thread that place

没有评论:

发表评论