|
|
|
Помогите разобраться
|
|||
|---|---|---|---|
|
#18+
Доброго всем дня!!! Помогите, пожалуйста, а то совсем запуталась!!! У меня есть JTable, у него 3 колонки, все постронные с помощью JLabel ( в первой картинка, в второй, текст и в третьей - картинка). Так вот мне нужно, чтоб при наведении мыши на третью колонку, менялся фон у лейбы Вот рендер для этой колонки public class ImagePlayRenderer extends DefaultTableCellRenderer { ImageIcon icon = new ImageIcon(Manager.class.getResource("play64.png")); public ImagePlayRenderer(){ } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setIcon(icon); setBackground(Color.WHITE); setHorizontalAlignment(JLabel.CENTER); setSize(64, 64); return this; } } вот так устанавливаю table.getColumnModel().getColumn(2).setCellRenderer(new ImagePlayRenderer()); Я разобралась, что MouseListener нужно устанавливать для таблицы, но все равно ничего не получается Большое всем спасибо ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 18.07.2014, 17:56 |
|
||
|
Помогите разобраться
|
|||
|---|---|---|---|
|
#18+
dudchenko, и что вы прописали в MouseListener? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 18.07.2014, 18:51 |
|
||
|
Помогите разобраться
|
|||
|---|---|---|---|
|
#18+
WarAnt, public class MouseByTableListener implements MouseListener { public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { JTable tabl = (JTable) e.getSource(); int x = e.getX(); int y = e.getY(); int row = tabl.rowAtPoint(new Point(x, y)); int col = tabl.columnAtPoint(new Point(x, y)); if(row > -1 && col == 2){ JLabel btn = (JLabel) tabl.getCellRenderer(row, col).getTableCellRendererComponent(tabl, e, false, false, row, col); btn.setBackground(Color.RED); tabl.repaint(); } } public void mouseExited(MouseEvent e) { JTable tabl = (JTable) e.getSource(); int x = e.getX(); int y = e.getY(); int row = tabl.rowAtPoint(new Point(x, y)); int col = tabl.columnAtPoint(new Point(x, y)); if(row > -1 && col == 2){ JLabel btn = (JLabel) tabl.getCellRenderer(row, col).getTableCellRendererComponent(tabl, e, false, false, row, col); btn.setBackground(Color.WHITE); tabl.repaint(); } } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } } ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 18.07.2014, 19:11 |
|
||
|
|

start [/forum/topic.php?fid=59&msg=38700748&tid=2126881]: |
0ms |
get settings: |
7ms |
get forum list: |
20ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
177ms |
get topic data: |
10ms |
get forum data: |
2ms |
get page messages: |
40ms |
get tp. blocked users: |
1ms |
| others: | 214ms |
| total: | 477ms |

| 0 / 0 |
