JLabel 클래스와 ImageIcon 클래스

✒️ 2025-05-15 14:27 내용 수정



JLabel 클래스

짧은 텍스트 또는 이미지를 보여주기 위한 공간을 생성하는 클래스

JLabel 인스턴스이름 = new JLabel();
오버로드된 다른 생성자
JLabel(Icon image)
JLabel(Icon image, int horizontalAlignment)
JLabel(String text)
JLabel(String text, Icon icon, int horizontalAlignment)
JLabel(String text, int horizontalAlignment)
메서드 설명
String getText() 라벨 디스플레이의 String text를 반환
void setText(String text) 디스플레이에 띄울 text를 지정
Icon getIcon() 라벨 디스플레이의 아이콘을 반환
void setIcon(Icon icon) 디스플레이에 띄울 아이콘을 지정
Icon getDisabledIcon() 라벨이 비활성화 됬을 때 표시할 아이콘을 반환
void setDisabledIcon(Icon disabledIcon) 라벨이 비활성화 됬을 때 표시할 아이콘을 지정
void setDisplayedMnemonic(int key) 디스플레이 단축키를 설정
void setDisplayedMnemonic(char aChar) 디스플레이 단축키를 설정
int getDisplayedMnemonic() 디스플레이 단축키를 반환
void setDisplayedMnemonicIndex(int index) 텍스트에서 단축키를 표시할 위치를 설정
int getDisplayedMnemonicIndex() 단축키로 지정한 문자를 인덱스로 반환
setHorizontalAlignment(JLabel.상수) x축에 대한 라벨의 내용 정렬 위치를 설정
int getHorizontalAlignment() x축에 대한 라벨의 내용 정렬 위치를 반환
setVerticalAlignment(JLabel.상수) y축에 대한 라벨의 내용 정렬 위치를 설정
int getVerticalAlignment() y축에 대한 라벨의 내용 정렬 위치를 반환
setHorizontalTextPosition(JLabel.상수) 라벨 텍스트의 수평 정렬 위치를 설정
int getHorizontalTextPosition() 라벨 텍스트의 수평 정렬 위치를 반환
setVerticalTextPosition(JLabel.상수) 라벨 텍스트의 수직 정렬 위치를 설정
int getHorizontalTextPosition() 라벨 텍스트의 수직 정렬 위치를 반환

ImageIcon 클래스

Java Swing에서 이미지를 나타내기 위해 사용하는 클래스

ImageIcon 인스턴스이름 = new ImageIcon();
오버로드된 다른 생성자
ImageIcon(String filename, String description)
ImageIcon (String filename)
ImageIcon(URL location, String description)
ImageIcon (URL location)
ImageIcon(Image image, String description)
ImageIcon (Image image)
ImageIcon (byte[] imageData, String description)
ImageIcon (byte[] imageData)