// education

고급 Swing 컴포넌트 활용 (JCheckBox, JRadioButton, JList, JComboBox)

실무 데스크톱 프로그램에서 널리 쓰이는 다양한 고급 스윙(Swing) 컴포넌트와 팝업 대화상자(JDialog)를 다룹니다.


1. 고급 컴포넌트 용어 사전 (Glossary)


2. 라디오 버튼과 콤보박스 활용 예제

import javax.swing.*;
import java.awt.*;

public class AdvancedComponentsFrame extends JFrame {
    public AdvancedComponentsFrame() {
        setTitle("고급 Swing 컴포넌트");
        setSize(400, 200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new FlowLayout());

        // 1. 라디오 버튼 그룹화
        JRadioButton r1 = new JRadioButton("남자");
        JRadioButton r2 = new JRadioButton("여자", true); // 기본 선택
        ButtonGroup group = new ButtonGroup();
        group.add(r1); group.add(r2);

        // 2. 드롭다운 콤보박스
        String[] cities = {"서울", "부산", "대구", "인천", "광주"};
        JComboBox<String> cityCombo = new JComboBox<>(cities);

        add(new JLabel("성별:")); add(r1); add(r2);
        add(new JLabel("거주지:")); add(cityCombo);

        setVisible(true);
    }

    public static void main(String[] args) {
        new AdvancedComponentsFrame();
    }
}

3. 자주 묻는 질문 (Q&A)

Q. JTextArea에 텍스트가 넘칠 때 스크롤바가 안 생기나요? A. JTextArea 자체에는 스크롤바가 없으므로 JScrollPane scrollPane = new JScrollPane(textArea); 형태로 스크롤 팬으로 감싸서 컨테이너에 배치해야 스크롤바가 생깁니다.

← 이전스트림 API(Stream API)를 활용한 데이터 파이프라인 다음 →자바 GUI 스윙(Swing) 컴포넌트와 이벤트 처리