KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > swing > editor > ButtonRenderer


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.mc4j.console.swing.editor;
18
19 import javax.swing.*;
20 import javax.swing.table.TableCellRenderer JavaDoc;
21 import java.awt.*;
22
23 /**
24  * @author Greg Hinkle (ghinkle@users.sourceforge.net), Feb 3, 2005
25  * @version $Revision: 570 $($Author: ghinkl $ / $Date: 2006-04-12 15:14:16 -0400 (Wed, 12 Apr 2006) $)
26  */

27 public class ButtonRenderer extends JButton implements TableCellRenderer JavaDoc {
28
29     public ButtonRenderer() {
30         setOpaque(true);
31     }
32
33     public Component getTableCellRendererComponent(
34         JTable table, Object JavaDoc value,
35         boolean isSelected, boolean hasFocus, int row, int column) {
36
37         if (isSelected) {
38             setForeground(table.getSelectionForeground());
39             setBackground(table.getSelectionBackground());
40         } else {
41             setForeground(table.getForeground());
42             setBackground(UIManager.getColor("Button.background"));
43         }
44         setText((value == null) ? "" : value.toString());
45         return this;
46     }
47 }
48
49
50
Popular Tags