|
JavaTM 2 Platform Std. Ed. v1. 4.0 |
||||||||||
| ÀüÀÇ Å¬·¡½º ´ÙÀ½ÀÇ Å¬·¡½º | ÇÁ·¹ÀÓ ÀÖ¾î ÇÁ·¹ÀÓ ¾øÀ½ | ||||||||||
| °³¿ä: »óÀÚ | Çʵå | constructor | ¸Þ¼Òµå | »ó¼¼: Çʵå | constructor | ¸Þ¼Òµå | ||||||||||
JList ³»ÀÇ ¼¿À» paint ÇÏ´Â ¡¸°í¹«Ç¥¡¹·Î¼ »ç¿ëÇÒ ¼ö ÀÖ´Â ÄÄÆÛ³ÍÆ®¸¦ ½Äº°ÇÕ´Ï´Ù. ¿¹¸¦ µé¾î, JLabel ¸¦ ListCellRenderer ·Î¼ »ç¿ëÇÏ·Á¸é , ´ÙÀ½°ú °°ÀÌ ¾¹´Ï´Ù.
class MyCellRenderer extends JLabel implements ListCellRenderer {
public MyCellRenderer() {
setOpaque(true);
}
public Component getListCellRendererComponent(
JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus)
{
setText(value.toString());
setBackground(isSelected ? Color.red : Color.white);
setForeground(isSelected ? Color.white : Color.black);
return this;
}
}
JList ,
DefaultListCellRenderer | ¸Þ¼ÒµåÀÇ °³¿ä | |
Component |
getListCellRendererComponent (JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus)
ÁöÁ¤ÀÇ °ªÀ» Ç¥½ÃÇϵµ·Ï(µíÀÌ) ¼³Á¤µÈ ÄÄÆÛ³ÍÆ®¸¦ µ¹·ÁÁÝ´Ï´Ù. |
| ¸Þ¼ÒµåÀÇ »ó¼¼ |
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus)
paint ¸Þ¼Òµå°¡ ºÒ·Á °¡, ¼¿À» ¡¸Ç¥Çö¡¹ÇÕ´Ï´Ù. ¸®½ºÆ® ¼¿ÀÇ »çÀÌÁî°¡ °íÁ¤µÇ¾î ÀÖÁö ¾Ê±â ¶§¹®¿¡, ¸®½ºÆ®ÀÇ Ä¡¼ö¸¦ °è»êÇÒ Çʿ䰡 ÀÖ´Â °æ¿ì¿¡´Â ÀÌ ¸Þ¼Òµå°¡ ºÒ·Á °¡,getPreferredSize ¸¦ È£ÃâÇÒ ¼ö ÀÖ´Â ÄÄÆÛ³ÍÆ®¸¦ »ý¼ºÇÕ´Ï´Ù.
list - paint Çϰí ÀÖ´Â JListvalue - list.getModel(). getElementAt(index)¿¡ ÀÇÇØ µ¹·ÁÁÖ¾îÁö´Â °ªindex - ¼¿ÀÇ À妽ºisSelected - ÁöÁ¤ÀÇ ¼¿ÀÌ ¼±ÅõǾúÀ» °æ¿ì´Â truecellHasFocus - ÁöÁ¤ÀÇ ¼¿¿¡ Æ÷Ä¿½º°¡ ÀÖ´Â °æ¿ì´Â true
JList ,
ListSelectionModel ,
ListModel
|
JavaTM 2 Platform Std. Ed. v1. 4.0 |
||||||||||
| ÀüÀÇ Å¬·¡½º ´ÙÀ½ÀÇ Å¬·¡½º | ÇÁ·¹ÀÓ ÀÖ¾î ÇÁ·¹ÀÓ ¾øÀ½ | ||||||||||
| °³¿ä: »óÀÚ | Çʵå | constructor | ¸Þ¼Òµå | »ó¼¼: Çʵå | constructor | ¸Þ¼Òµå | ||||||||||
Java, Java 2 D, ¹× JDBC ´Â ¹Ì±¹ ¹× ±× ¿ÜÀÇ ³ª¶ó¿¡ ÀÖ¾î¼ÀÇ ¹Ì±¹ Sun Microsystems, Inc. ÀÇ »óÇ¥ ȤÀº µî·Ï»óÇ¥ÀÔ´Ï´Ù.
Copyright 1993-2002 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.