JMenu 클래스
✒️ 2025-05-15 13:59 내용 수정
- JMenu와 연관된 클래스들은 setJMenuBar() 메서드를 제공하는 Container 객체에서만 사용할 수 있다.
- 최종 Container인 JFrame에서만 사용 가능하다.
- Component 클래스, JComponent 클래스, Container 클래스를 상속 받기 때문에 해당 클래스들의 메서드를 사용할 수 있다.
- JFrame에 적어둔 메서드와도 사용 가능한 메서드가 겹친다.
- 자주 사용했던 메서드만 적어두었다.
- JFrame 클래스#메서드 참고
JMenuBar 클래스
JComponent 클래스를 상속받고 메뉴 바를 구현하는 클래스
JMenuBar() 인스턴스이름 = new JMenuBar();
JMenuItem 클래스
AbstractButton 클래스를 상속받고, 메뉴에서의 아이템을 구현하는 클래스
JMenuItem() 인스턴스이름 = new JMenuItem();
| 생성자 |
|---|
JMenuItem(Icon icon) |
JMenuItem(String text) |
JMenuItem(Action a) |
JMenuItem(String text, Icon icon) |
JMenuItem(String text, int mnemonic) |
JMenu 클래스
JMenuItem 클래스를 상속받고 메뉴창을 띄우는 클래스
JMenu() 인스턴스이름 = new JMenu();
| 생성자 |
|---|
JMenu(String s) |
JMenu(Action a) |
JMenu(String s, boolean b) |
JRadioButtonMenuItem 클래스
JMenuItem 클래스를 상속받고, RadioButton 메뉴를 구현한 클래스
JRadioButtonMenuItem 인스턴스이름 = new JRadioButtonMenuItem();
| 생성자 |
|---|
JRadioButtonMenuItem(Icon icon) |
JRadioButtonMenuItem(String text) |
JRadioButtonMenuItem(String text, Icon icon) |
JRadioButtonMenuItem(String text, boolean selected) |
JRadioButtonMenuItem(Icon icon, boolean selected) |
JRadioButtonMenuItem(String text, Icon icon, boolean selected) |
JPopupMenu 클래스
JComponent 클래스를 상속받고, 팝업 메뉴를 구현한 클래스
JPopupMenu 인스턴스이름 = new JPopupMenu();
JPopupMenu 인스턴스이름 = new JPopupMenu(String label);
| 메서드 | 설명 |
|---|---|
JMenuItem add(JMenuItem menuItem) |
전달 받은 메뉴 아이템을 추가 |
JMenuItem add(String s) |
전달 받은 String을 추가 |
JMenuItem add(Action a) |
전달 받은 Action을 추가 |
void remove(int pos) |
팝업 메뉴에서 인덱스가 pos인 Component를 제거 |
String getLabel() |
팝업 메뉴의 Label을 반환 |
void setLabel(String label) |
팝업 메뉴의 새 Label을 설정 |
void insert(Action a, int index) |
팝업 메뉴의 index위치에 Action 객체를 추가 |
void insert(Component component, int index) |
팝업 메뉴의 index위치에 Component를 추가 |
addPopupMenuListener(PopupMenuListener l) |
PopupMenuListener를 추가 |
void removePopupMenuListener(PopupMenuListener l) |
PopupMenuListener를 제거 |
PopupMenuListener[] getPopupMenuListeners() |
PopupMenuListener들의 배열을 반환 |
void setVisible(boolean b) |
팝업 메뉴를 보이게 할지 설정 |
void showPopup() |
팝업 메뉴를 보여줌 |
void setLocation(int x, int y) |
팝업 메뉴 위치를 설정 |