'JSplitPane 예제'에 해당되는 글 1건

  1. 2016.12.21 JSplitPane 예제

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JSplitPane;

import javax.swing.JTextArea;


public class JSplitPaneTest extends JFrame{

JSplitPane sp1, sp2;

public JSplitPaneTest() {

sp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JTextArea("위"), new RGB2());

sp2.setDividerLocation(300);

sp1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JButton("확인"), sp2);

sp1.setDividerLocation(300); //경계선의 위치

//sp1.setDividerSize(5); //경계선의 두께

sp1.setOneTouchExpandable(true); //경계선 내에 확장, 축소 버튼 표시

add(sp1, "Center");

setSize(800, 600);

setVisible(true);

}


public static void main(String[] args) {

new JSplitPaneTest();

}


}

=====================================================================
RGB 소스

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class RGB2 extends JPanel implements ChangeListener{
JLabel rgbLbl = new JLabel("RGB(150, 150, 150)", JLabel.CENTER);
JPanel rgbView = new JPanel();
int red=150, green=150, blue=150;
Color color = new Color(150, 150, 150);
//패널만들기
JPanel rgbInfo = new JPanel(new BorderLayout());
JPanel labelPane = new JPanel(new GridLayout(3, 1));
JLabel redLbl = new JLabel("RED");
JLabel greenLbl = new JLabel("GREEN");
JLabel blueLbl = new JLabel("BLUE");
JPanel sliderPane = new JPanel(new GridLayout(3, 1));
JSlider redSlider = new JSlider(0, 255, 150);
JSlider greenSlider = new JSlider(0, 255, 150);
JSlider blueSlider = new JSlider(0, 255, 150);
JPanel colorPane = new JPanel(new GridLayout(3, 1));
JLabel redClrLbl = new JLabel("                    ");
JLabel greenClrLbl = new JLabel("                    ");
JLabel blueClrLbl = new JLabel("                    ");
public RGB2() {
setLayout(new BorderLayout());
add(rgbLbl, "North");
rgbView.setBackground(color); //패널컬러세팅
add(rgbView, "Center");
labelPane.add(redLbl); labelPane.add(greenLbl); labelPane.add(blueLbl);
rgbInfo.add(labelPane, "West");
redSlider.setMajorTickSpacing(50);
redSlider.setMinorTickSpacing(5);
redSlider.setPaintTicks(true);
redSlider.setPaintLabels(true);
greenSlider.setMajorTickSpacing(50);
greenSlider.setMinorTickSpacing(5);
greenSlider.setPaintTicks(true);
greenSlider.setPaintLabels(true);
blueSlider.setMajorTickSpacing(50);
blueSlider.setMinorTickSpacing(5);
blueSlider.setPaintTicks(true);
blueSlider.setPaintLabels(true);
sliderPane.add(redSlider); sliderPane.add(greenSlider); sliderPane.add(blueSlider);
rgbInfo.add(sliderPane, "Center");
LineBorder lb = new LineBorder(Color.CYAN, 3);
TitledBorder tb = new TitledBorder(lb, "Color Split", TitledBorder.CENTER, 
TitledBorder.CENTER, new Font("Serif", Font.BOLD, 15), Color.BLACK);
rgbInfo.setBorder(tb);
redClrLbl.setOpaque(true);
redClrLbl.setBackground(new Color(150, 0, 0));
greenClrLbl.setOpaque(true);
greenClrLbl.setBackground(new Color(0, 150, 0));
blueClrLbl.setOpaque(true);
blueClrLbl.setBackground(new Color(0, 0, 150));
colorPane.add(redClrLbl); colorPane.add(greenClrLbl); colorPane.add(blueClrLbl);
rgbInfo.add(colorPane, "East");
add(rgbInfo, "South");
// setSize(500, 350);
// setVisible(true);

//이벤트 등록
redSlider.addChangeListener(this);
greenSlider.addChangeListener(this);
blueSlider.addChangeListener(this);
}
public void stateChanged(ChangeEvent ce){
Object obj = ce.getSource();
if(obj == redSlider){
red = redSlider.getValue();
redClrLbl.setBackground(new Color(red, 0, 0));
}else if(obj == greenSlider){
green = greenSlider.getValue();
greenClrLbl.setBackground(new Color(0, green, 0));
}else if(obj == blueSlider){
blue = blueSlider.getValue();
blueClrLbl.setBackground(new Color(0, 0, blue));
}
rgbView.setBackground(new Color(red, green, blue));
rgbLbl.setText("RGB("+red+", "+green+", "+blue+")");
}
}


'응용 SoftWare > JAVA' 카테고리의 다른 글

Class Test  (0) 2016.12.23
JSplitPane 예제2  (0) 2016.12.21
JTree 예제  (0) 2016.12.21
Thread를 이용한 디지털 시계  (0) 2016.12.21
[Swing] 달력만들기  (0) 2016.12.16
Posted by Hyun CHO
,