2024-03-30
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# tmpl-java-library
|
# Swing Examples
|
||||||
|
|
||||||
Template for Java library project
|
Swing Examples
|
||||||
|
|
||||||
---
|
---
|
||||||
developed by Elex
|
developed by Elex
|
||||||
|
|||||||
111
build.gradle.kts
111
build.gradle.kts
@@ -1,7 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
java
|
java
|
||||||
`java-library`
|
|
||||||
`maven-publish`
|
|
||||||
idea
|
idea
|
||||||
id("com.github.ben-manes.versions") version "0.51.0"
|
id("com.github.ben-manes.versions") version "0.51.0"
|
||||||
}
|
}
|
||||||
@@ -19,10 +17,6 @@ repositories {
|
|||||||
password = project.findProperty("repo.password") as String
|
password = project.findProperty("repo.password") as String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
maven {
|
|
||||||
url = uri("https://repo.maven.apache.org/maven2")
|
|
||||||
name = "Maven Central"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
idea{
|
idea{
|
||||||
module {
|
module {
|
||||||
@@ -31,10 +25,10 @@ idea{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
java {
|
java {
|
||||||
withSourcesJar()
|
//withSourcesJar()
|
||||||
withJavadocJar()
|
//withJavadocJar()
|
||||||
sourceCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
|
sourceCompatibility = org.gradle.api.JavaVersion.VERSION_17
|
||||||
targetCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
|
targetCompatibility = org.gradle.api.JavaVersion.VERSION_17
|
||||||
//modularity.inferModulePath.set(false)
|
//modularity.inferModulePath.set(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,95 +75,16 @@ tasks.javadoc {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
create<MavenPublication>("mavenJava") {
|
|
||||||
from(components["java"])
|
|
||||||
pom {
|
|
||||||
// todo
|
|
||||||
name.set(project.name)
|
|
||||||
description.set(project.description)
|
|
||||||
url.set("https://www.elex-project.com/")
|
|
||||||
inceptionYear.set("2022")
|
|
||||||
properties.set(mapOf(
|
|
||||||
"myProp" to "value",
|
|
||||||
"prop.with.dots" to "anotherValue"
|
|
||||||
))
|
|
||||||
organization {
|
|
||||||
name.set("Elex co.,Pte.")
|
|
||||||
url.set("https://www.elex-project.com/")
|
|
||||||
}
|
|
||||||
licenses {
|
|
||||||
license {
|
|
||||||
// todo
|
|
||||||
name.set("Apache License 2.0")
|
|
||||||
url.set("https://git.elex-project.com/elex/${project.name}/src/branch/main/LICENSE")
|
|
||||||
comments.set("")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
developers {
|
|
||||||
developer {
|
|
||||||
id.set("elex")
|
|
||||||
name.set("Elex")
|
|
||||||
url.set("https://www.elex.pe.kr/")
|
|
||||||
email.set("developer@elex-project.com")
|
|
||||||
organization.set("Elex Co.,Pte.")
|
|
||||||
organizationUrl.set("https://www.elex-project.com/")
|
|
||||||
roles.set(arrayListOf("Developer", "CEO"))
|
|
||||||
timezone.set("Asia/Seoul")
|
|
||||||
properties.set(mapOf("" to ""))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
contributors {
|
|
||||||
contributor {
|
|
||||||
name.set("")
|
|
||||||
email.set("")
|
|
||||||
url.set("")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
scm {
|
|
||||||
// todo
|
|
||||||
connection.set("scm:git:https://git.elex-project.com/elex/${project.name}.git")
|
|
||||||
developerConnection.set("scm:git:https://git.elex-project.com/elex/${project.name}.git")
|
|
||||||
url.set("https://git.elex-project.com/elex/${project.name}/")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
maven {
|
|
||||||
name = "mavenElex"
|
|
||||||
val urlRelease = uri(project.findProperty("repo.release.url") as String)
|
|
||||||
val urlSnapshot = uri(project.findProperty("repo.snapshot.url") as String)
|
|
||||||
url = if (version.toString().endsWith("SNAPSHOT")) urlSnapshot else urlRelease
|
|
||||||
// Repository credential, Must be defined in ~/.gradle/gradle.properties
|
|
||||||
credentials {
|
|
||||||
username = project.findProperty("repo.username") as String
|
|
||||||
password = project.findProperty("repo.password") as String
|
|
||||||
}
|
|
||||||
}
|
|
||||||
maven { //todo
|
|
||||||
name = "mavenGithub"
|
|
||||||
url = uri("https://maven.pkg.github.com/elex-project/${project.name}")
|
|
||||||
credentials {
|
|
||||||
username = project.findProperty("github.username") as String
|
|
||||||
password = project.findProperty("github.token") as String
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
|
//implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
|
||||||
implementation("org.slf4j:slf4j-api:2.1.0-alpha1")
|
implementation("org.slf4j:slf4j-api:2.+")
|
||||||
implementation("org.jetbrains:annotations:24.1.0")
|
implementation("org.jetbrains:annotations:24.+")
|
||||||
|
|
||||||
compileOnly("org.projectlombok:lombok:1.18.30")
|
compileOnly("org.projectlombok:lombok:1.18.32")
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.26")
|
annotationProcessor("org.projectlombok:lombok:1.18.32")
|
||||||
testAnnotationProcessor("org.projectlombok:lombok:1.18.26")
|
testAnnotationProcessor("org.projectlombok:lombok:1.18.32")
|
||||||
|
|
||||||
testImplementation("ch.qos.logback:logback-classic:1.4.14")
|
testImplementation("ch.qos.logback:logback-classic:1.5.3")
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter:5.10.1")
|
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
|
||||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1")
|
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2")
|
||||||
}
|
}
|
||||||
|
|||||||
57
doc/01_top_level_containers.md
Normal file
57
doc/01_top_level_containers.md
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
# 최상위 컨데이너
|
||||||
|
JFrame, JDialog, JApplet 등이 최상위 컨테이너이며, 프로그램 창(윈도우)이라고도 이해할 수 있다.
|
||||||
|
최상위 컨테이너는 시각적 컴포넌트를 위한 영역인 content pane을 가지고 있다.
|
||||||
|
|
||||||
|
## JFrame
|
||||||
|
|
||||||
|
* `getDefaultCloseOperation()` / `setDefaultCloseOperation(int)` : DO_NOTHING_ON_CLOSE | HIDE_ON_CLOSE | DISPOSE_ON_CLOSE | EXIT_ON_CLOSE
|
||||||
|
* `getIconImage()` / `setIconImage(java.awt.Image)`
|
||||||
|
* `getTitle()` / `setTitle(String)`
|
||||||
|
* `isUndecorated()` / `setUndecorated(boolean)`
|
||||||
|
* `isDefaultLookAndFeelDecorated()` / `setDefaultLookAndFeelDecorated(boolean)`
|
||||||
|
|
||||||
|
* `getSize()` / `setSize(int,int)` / `setSize(Dimension)`
|
||||||
|
* `getBounds()` / `setBounds(int,int,int,int)` / `setBounds(Rectangle)` : x, y, width, height
|
||||||
|
* `getLocation()` / `setLocation(int,int)` / `setLocationRelativeTo(Component)`
|
||||||
|
* `pack()`
|
||||||
|
|
||||||
|
* `getContentPane()` / `setContentPnae(Container)`
|
||||||
|
* `getRootPane()` / `setRootPane(JRootPane)` / `createRootPane()`
|
||||||
|
* `getJMenuBar()` / `setJMenuBar(JMenuBar)`
|
||||||
|
* `getGlassPane()` / `setGlassPane(Component)`
|
||||||
|
* `getLayeredPane()` / `setLayeredPane(JLayeredPane)`
|
||||||
|
|
||||||
|
|
||||||
|
```java
|
||||||
|
public static void main(String... args) {
|
||||||
|
// 컨텐트 패널에 버튼 등의 컴포넌트를 구성한다.
|
||||||
|
final JPanel contentPane = new JPanel();
|
||||||
|
contentPane.setBackground(Color.PINK);
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(contentPane);
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## JDialog
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Full-screen Exclusive mode
|
||||||
|
|
||||||
|
```java
|
||||||
|
if(graphicsDevice.isFullScreenSupported()){
|
||||||
|
graphicsDevice.setFullScreenWindow(jFrame);
|
||||||
|
// graphicsDevice.setFullScreenWindow(null); //null to exit
|
||||||
|
}
|
||||||
|
```
|
||||||
|
### DisplayMode
|
||||||
99
doc/02_basic_component_methods.md
Normal file
99
doc/02_basic_component_methods.md
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
# 컴포넌트 공통 사항
|
||||||
|
|
||||||
|
## 스타일
|
||||||
|
* `getBorder()` / `setBorder(Border)`
|
||||||
|
* `getForeground()` / `setForeground(Color)`
|
||||||
|
* `getBackground()` / `setBackground(Color)`
|
||||||
|
* `isOpaque()` / `setOpague(boolean)`
|
||||||
|
* `getFont()` / `setFont(Font)`
|
||||||
|
* `getCursor()` / `setCursor(Cursor)`
|
||||||
|
|
||||||
|
```java
|
||||||
|
myComponent.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
|
||||||
|
myComponent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||||
|
myComponent.setBackground(Color.PINK);
|
||||||
|
```
|
||||||
|
|
||||||
|
## 상태
|
||||||
|
* `isEnabled()` / `setEnabled(boolean)`
|
||||||
|
* `isVisible()` / `setVisible(boolean)`
|
||||||
|
* `isShowing()`
|
||||||
|
* `getName()` / `setName(String)` : 컴포넌트에 관리용 이름을 붙일 때 사용할 수 있다.
|
||||||
|
* `setTooltipText()`
|
||||||
|
* `getTransferHandler()` / `setTransferHandlerTransferHandler()` : 드래그&드롭에서 사용한다.
|
||||||
|
* `setComponentPopupMenu(JPopupMenu)`
|
||||||
|
|
||||||
|
## 리스너
|
||||||
|
* `addXXXListener()` / `removeXXXListener()`
|
||||||
|
* HierarchyListener
|
||||||
|
* MouseListener
|
||||||
|
* MouseMotionListener
|
||||||
|
* KeyListener
|
||||||
|
* ComponentListener
|
||||||
|
|
||||||
|
## 컴포넌트
|
||||||
|
* `add(Component)` / `add(Component,int)` / `add(Component,Object)`
|
||||||
|
* `remove(int)` / `remove(Component)` / `removeAll()`
|
||||||
|
* `contains(int,int)` / `contains(Point)` : 주어진 좌표가 컴포넌트 내부인가?
|
||||||
|
* `getComponentAt(int,int)` / `getComponentAt(Point)`
|
||||||
|
* `getComponentZOrder(Component)` / `setComponentZOrder(Component,int)`
|
||||||
|
* `getComponentZOrder(int)` / `getComponentZOrder()`
|
||||||
|
* `getRootPane()` / `getTopLevelAnscestor()` / `getParent()`
|
||||||
|
* `getComponentCount()`
|
||||||
|
* `getComponent(int)` / `getComponents()`
|
||||||
|
|
||||||
|
## 레이아웃
|
||||||
|
* `getLayout()` / `setLayout(LayoutManager)`
|
||||||
|
* `getPreferredSize()` / `setPreferredSize(Dimension)`
|
||||||
|
* `getMaximumSize()` / `setMaximumSize(Dimension)`
|
||||||
|
* `getMinimumSize()` / `setMinimumSize(Dimension)`
|
||||||
|
* `getAlignmentX()` / `setAlignmentX(float)`
|
||||||
|
* `getAlignmentY()` / `setAlignmentY(float)`
|
||||||
|
* `applyComponentOrientation(ComponentOrientation)` / `setComponentOrientation(ComponentOrientation)`
|
||||||
|
|
||||||
|
## 위치와 크기
|
||||||
|
* `getX()` / `getY()`
|
||||||
|
* `getWidth()` / `getHeight()`
|
||||||
|
* `getSize()` / `setSize(Dimension)`
|
||||||
|
* `getBounds()` / `setBounds(Rectangle)`
|
||||||
|
* `getLocation()` / `setLocation(Point)`
|
||||||
|
* `getLocationOnScreen()`
|
||||||
|
* `getInsets()` / `setInsets(Inset)`
|
||||||
|
|
||||||
|
## 패인팅
|
||||||
|
* `repaint()` / `repaint(int,int,int,int)` / `repaint(Rectangle)`
|
||||||
|
* `revalidate()`
|
||||||
|
* `paintComponent(Graphics)` : 이 메서드를 오버라이드해서 커스텀 컴포넌트를 만든다.
|
||||||
|
|
||||||
|
|
||||||
|
## Focus
|
||||||
|
|
||||||
|
* `isFocusOwner()`
|
||||||
|
* `isRequestFocusEnabled()` / `setRequestFocusEnabled(boolean)`
|
||||||
|
* `isFocusable()` / `setFocusable(boolean)`
|
||||||
|
* `requestFocusInWindow()`
|
||||||
|
* `getFocusTraversalKeys(int)` / `setFocusTraversalKeys(int,Set)` / `areFocusTraversalKeysSet(int)`
|
||||||
|
|
||||||
|
|
||||||
|
### LayoutFocusTraversalPolicy
|
||||||
|
|
||||||
|
* `getComponentAfter(Container,Component)`
|
||||||
|
* `getComponentBefore(Container,Component)`
|
||||||
|
* `getFirstComponent(Container)` / `getInitialComponent(Container)` / `getLastComponent(Container)`
|
||||||
|
|
||||||
|
|
||||||
|
* `container.getFocusTraversalPolicy()` / `container.setFocusTraversalPolicy(FocusTraversalPolicy)`
|
||||||
|
* `container.isFocusCycleRoot()` / `container.setFocusCycleRoot(boolean)`
|
||||||
|
* `container.isFocusTraversalPolicyProvider()` / `container.setFocusTraversalPolicyProvider(boolean)`
|
||||||
|
|
||||||
|
|
||||||
|
## InputMap
|
||||||
|
|
||||||
|
* `component.getInputMap()` / `component.getInputMap(int)` : JComponent.WHEN_FOCUSED | WHEN_IN_FOCUSED_WINDOW | WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
|
||||||
|
* `put(KeyStroke,Object)` : 키 스트록, 액션명. 키와 이름을 연결시킨다.
|
||||||
|
* `KeyStroke.getKeyStroke(String)`
|
||||||
|
|
||||||
|
## ActionMap
|
||||||
|
|
||||||
|
* `component.getActionMap()`
|
||||||
|
* `put(Object,Action)` : 이름과 액션을 연결시킨다.
|
||||||
192
doc/03_text_components.md
Normal file
192
doc/03_text_components.md
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
# 텍스트 컴포넌트
|
||||||
|
|
||||||
|
* `isEditable()` / `setEditable(boolean)`
|
||||||
|
* `getDragEnabled()` / `setDragEnabled(boolean)`
|
||||||
|
* `getDisabledTextColor()` / `setDisabledTextColor(Color)`
|
||||||
|
* `getMargin()` / `setMargin(Insets)` : 텍스트와 컴포넌트 보더 사이 간격
|
||||||
|
|
||||||
|
* `getSelectedText()`
|
||||||
|
* `select(int,int)` / `selectAll()`
|
||||||
|
* `getSelectionStart()` / `setSelectionStart(int)` / `getSelectionEnd()` / `setSelectionEnd(int)`
|
||||||
|
* `getSelectionColor()` / `setSelectionColor(Color)`
|
||||||
|
* `getSelectedTextColor()` / `setSelectedTextColor(Color)`
|
||||||
|
|
||||||
|
* `viewToModel(Point)` / `modelToView(int)`
|
||||||
|
|
||||||
|
* `copy()` / `cut()` / `paste()` / `replaceSelection(String)`
|
||||||
|
* `getActions()`
|
||||||
|
* `getInputMap()`
|
||||||
|
* `put(KeyStroke,Object)`
|
||||||
|
|
||||||
|
* `getDocument()` / `setDocument(Document)`
|
||||||
|
* `setDocumentFilter(DocumentFilter)`
|
||||||
|
|
||||||
|
* `getCaret()` / `setCaret(Caret)`
|
||||||
|
* `getCaretColor()` / `setCaretColor(Color)`
|
||||||
|
* `getCaretPosition()` / `moveCaretPosition(int)` / `setCaretPosition(int)`
|
||||||
|
* `addCaretListener()` / `removeCaretListener()`
|
||||||
|
|
||||||
|
* `setNavigationFilter()`
|
||||||
|
* `getHighlighter()` / `setHighlighter(Highlighter)`
|
||||||
|
|
||||||
|
* `read(Reader, Object)` / `write(Writer)`
|
||||||
|
|
||||||
|
* `print()` / `print(MessageFormat,MessageFormat)`
|
||||||
|
* `getPrintable(MessageFormat,MessageFormat)`
|
||||||
|
|
||||||
|
## Document
|
||||||
|
* `addDocumentListener()` / `removeDocumentListener()`
|
||||||
|
* `addUndoableEditListener()` / `removeUndoableEditListener()`
|
||||||
|
* `getLength()`
|
||||||
|
* `getStartPosition()` / `getEndPosition()`
|
||||||
|
* `getText(int,int)`
|
||||||
|
* `getProperty(Object)` / `putProperty(Object,Object)` / `getDocumentProperties()` / `setDocumentProperties(Dictionary)`
|
||||||
|
|
||||||
|
## Undo / Redo 구현 - UndoableEditListener
|
||||||
|
```java
|
||||||
|
// 언두 매니저를 생성하고, 텍스트 문서에 리스너를 통해 연결한다.
|
||||||
|
final UndoManager undoManager = new UndoManager();
|
||||||
|
textArea.getDocument().addUndoableEditListener(undoableEditEvent ->
|
||||||
|
undoManager.addEdit(undoableEditEvent.getEdit()));
|
||||||
|
|
||||||
|
// 버튼을 통해서 액션을 처리한다.
|
||||||
|
toolBar.add(new AbstractAction("Undo") {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
if (undoManager.canUndo()) {
|
||||||
|
undoManager.undo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
toolBar.add(new AbstractAction("Redo") {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
if (undoManager.canRedo()) {
|
||||||
|
undoManager.redo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## DocumentListener
|
||||||
|
```java
|
||||||
|
textArea.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
|
@Override
|
||||||
|
public void insertUpdate(DocumentEvent documentEvent) {
|
||||||
|
Document document = documentEvent.getDocument();
|
||||||
|
int changeLength = documentEvent.getLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeUpdate(DocumentEvent documentEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changedUpdate(DocumentEvent documentEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## CaretListener
|
||||||
|
```java
|
||||||
|
textArea.addCaretListener(new CaretListener() {
|
||||||
|
@Override
|
||||||
|
public void caretUpdate(CaretEvent caretEvent) {
|
||||||
|
int dot = caretEvent.getDot();
|
||||||
|
int mark = caretEvent.getMark();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## JTextField
|
||||||
|
|
||||||
|
* `getText()` / `setText(String)`
|
||||||
|
* `isEditable()` / `setEditable(boolean)`
|
||||||
|
* `getColumns()` / `setColumns(int)` : 화면에 표시될 칼럼 길이
|
||||||
|
|
||||||
|
* `selectAll()`
|
||||||
|
|
||||||
|
* `getHorizontalAlignment()` / `setHorizontalAlignment(int)` : JTextField.LEADING | CENTER | TRAILING
|
||||||
|
|
||||||
|
* `addActionListener()` / `removeActionListener()`
|
||||||
|
|
||||||
|
## JPasswordField
|
||||||
|
|
||||||
|
* `char[] getPassword()`
|
||||||
|
* `getEchoChar()` / `setEchoChar(char)`
|
||||||
|
|
||||||
|
## JFormattedTextField
|
||||||
|
|
||||||
|
* `JFormattedTextField()` / `JFormattedTextField(Format)` / `JFormattedTextField(Formatter)` / `JFormattedTextField(FormatterFactory)`
|
||||||
|
|
||||||
|
* `getValue()` / `setValue(Object)`
|
||||||
|
* `getFormatter()` / `setFormatterFactory()`
|
||||||
|
* `setFocusLostBehavior(int)` : COMMIT_OR_REVERT | COMMIT | PERSIST | REVERT
|
||||||
|
* `commitEdit()`
|
||||||
|
* `isEditValid()`
|
||||||
|
|
||||||
|
### Format
|
||||||
|
* DateFormatter
|
||||||
|
* NumberFormatter
|
||||||
|
* InternationalFormatter
|
||||||
|
* MaskFormatter
|
||||||
|
* DateFormat
|
||||||
|
* SimpleDateFormat
|
||||||
|
* NumberFormat
|
||||||
|
* DefaultFormatterFactory
|
||||||
|
* DefaultFormatter
|
||||||
|
|
||||||
|
#### DefaultFormatter
|
||||||
|
|
||||||
|
* `getCommitsOnValidEdit()` / `setCommitsOnValidEdit(boolean)`
|
||||||
|
* `getOverwriteMode()` / `setOverwriteMode(boolean)`
|
||||||
|
* `getAllowsInvalid()` / `setAllowsInvalid(boolean)`
|
||||||
|
|
||||||
|
#### MaskFormatter
|
||||||
|
* `#` 아무 숫자 하나
|
||||||
|
* `'` 이스케잎문자로 사용됨
|
||||||
|
* `U` 대문자 하나
|
||||||
|
* `L` 소문자 하나
|
||||||
|
* `A` 문자 또는 숫자 하나
|
||||||
|
* `?` 문자 하나
|
||||||
|
* `*` 아무거나
|
||||||
|
* `H` 16진수문자 하나
|
||||||
|
|
||||||
|
## JTextArea
|
||||||
|
|
||||||
|
* `JTextArea()` / `JTextArea(String)` / `JTextArea(int,int)` / `JTextArea(String,int,int)` : 칼럼 갯수, 열 갯수
|
||||||
|
|
||||||
|
* `getText()` / `setText(String)`
|
||||||
|
|
||||||
|
* `isEditable()` / `setEditable(boolean)`
|
||||||
|
* `getColumns()` / `setColumns(int)`
|
||||||
|
* `getRows()` / `setRows(int)`
|
||||||
|
* `setTabSize(int)`
|
||||||
|
* `setLineWrap(boolean)`
|
||||||
|
* `setWrapStyleWord(boolean)`
|
||||||
|
|
||||||
|
* `selectAll()`
|
||||||
|
|
||||||
|
* `append(String)`
|
||||||
|
* `insert(String,int)`
|
||||||
|
* `replaceRange(String,int,int)`
|
||||||
|
* `getLineCount()`
|
||||||
|
* `getLineOfOffset(int)`
|
||||||
|
* `getLineStartOffset(int)`
|
||||||
|
* `getLineEndOffset(int)`
|
||||||
|
|
||||||
|
## JEditorPane
|
||||||
|
|
||||||
|
## JTextPane
|
||||||
|
|
||||||
58
doc/04_buttons.md
Normal file
58
doc/04_buttons.md
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
# 버튼
|
||||||
|
|
||||||
|
## AbstractButton
|
||||||
|
* `getAction()` / `setAction(Action)`
|
||||||
|
* `getText()` / `setText(String)`
|
||||||
|
* `getIcon()` / `setIcon(Icon)`
|
||||||
|
* `getDisabledIcon()` / `setDisabledIcon(Icon)`
|
||||||
|
* `getPressedIcon()` / `setPressedIcon(Icon)`
|
||||||
|
* `getSelectedIcon()` / `setSelectedIcon(Icon)`
|
||||||
|
* `getDisabledSelectedIcon()` / `setDisabledSelectedIcon(Icon)`
|
||||||
|
* `getRolloverIcon()` / `setRolloverIcon(Icon)`
|
||||||
|
* `getRolloverSelectedIcon()` / `setRolloverSelectedIcon(Icon)`
|
||||||
|
* `isRolloverEnabled()` / `setRolloverEnabled(boolean)`
|
||||||
|
|
||||||
|
* `getHorizontalAlignment()` / `setHorizontalAlignment(int)` : AbstractButton의 상수를 사용. CENTER | RIGHT | LEFT | LEADING | TRAILING
|
||||||
|
* `getVerticalAlignment()` / `setVerticalAlignment(int)` : CENTER | TOP | BOTTOM
|
||||||
|
* `getMargin()` / `setMargin(Insets)`
|
||||||
|
* `isFocusPainted()` / `setFocusPainted(boolean)`
|
||||||
|
* `isBorderPainted()` / `setBorderPainted(boolean)`
|
||||||
|
* `getIconTextGap()` / `setIconTextGap(int)`
|
||||||
|
|
||||||
|
* `getMnemonic()` / `setMnemonic(int)` : KeyEvent의 상수를 사용
|
||||||
|
* `getDisplayedMnemonicIndex()` / `setDisplayedMnemonicIndex(int)`
|
||||||
|
* `getActionCommand()` / `setActionCommand(String)`
|
||||||
|
* `addActionListener()` / `removeActionListener()`
|
||||||
|
* `addItemListener()` / `removeItemListener()`
|
||||||
|
* `isSelected()` / `setSelected(boolean)`
|
||||||
|
* `doClick()` / `doClick(int)` : 버튼을 클릭한 시간을 밀리초 단위로 지정할 수도 있다.
|
||||||
|
* `getMultiClickThreshhold()` / `setMultiClickThreshhold(long)` : 지정 시간 이내의 이벤트는 중복으로 무시한다.
|
||||||
|
|
||||||
|
## JButton
|
||||||
|
|
||||||
|
## JCheckBox
|
||||||
|
|
||||||
|
## JToggleButton
|
||||||
|
|
||||||
|
## 버튼 그룹 - ButtonGroup
|
||||||
|
* `add(AbstractButton)` / `remove(AbstractButton)`
|
||||||
|
* `clearSelection()`
|
||||||
|
|
||||||
|
```java
|
||||||
|
// 버튼에 할당된 버튼 그룹을 가져오려는 경우
|
||||||
|
ButtonGroup group = ((DefaultButtonModel)button.getModel()).getGroup();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Action
|
||||||
|
### AbstractAction
|
||||||
|
|
||||||
|
* `isEnabled()` / `setEnabled(boolean)`
|
||||||
|
* `getValue(String)` / `putValue(String,Object)`
|
||||||
|
* ACCELERATOR_KEY : KeyStroke
|
||||||
|
* ACTION_COMMAND_KEY : String
|
||||||
|
* LONG_DESCRIPTION
|
||||||
|
* MNEMONIC_KEY
|
||||||
|
* NAME
|
||||||
|
* SHORT_DESCRIPTION
|
||||||
|
* SMALL_ICON
|
||||||
46
doc/05_file_cooser_color_chooser.md
Normal file
46
doc/05_file_cooser_color_chooser.md
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# Color Chooser
|
||||||
|
|
||||||
|
|
||||||
|
* `JColorChooser()` / `JColorChooser(Color)`
|
||||||
|
|
||||||
|
|
||||||
|
* `showDialog()` / `createDialog()`
|
||||||
|
* `getPreviewPanel()` / `setPreviewPanel()`
|
||||||
|
* `getChooserPanels()` / `setChooserPanels(AbstractColorChooserPanel[])`
|
||||||
|
* `addChooserPanel()` / `removeChooserPanel()`
|
||||||
|
* `getDragEnabled()` / `setDragEnabled(boolean)`
|
||||||
|
* `getColor()` / `setColor()`
|
||||||
|
* `getSelectionModel()` / `setSelectionModel()`
|
||||||
|
|
||||||
|
|
||||||
|
# File Chooser
|
||||||
|
|
||||||
|
|
||||||
|
* `JFileChooser()` / `JFileChooser(File)` : 초기 경로를 지정할 수 있다.
|
||||||
|
|
||||||
|
|
||||||
|
* `int showOpenDialog(Component)` : APPROVE_OPTION | CANCEL_OPTION | ERROR_OPTION
|
||||||
|
* `int showSaveDialog(Component)`
|
||||||
|
* `int showDialog(Component,Stirng)`
|
||||||
|
|
||||||
|
|
||||||
|
* `getSelectedFile()` / `setSelectedFile(File)`
|
||||||
|
* `getSelectedFiles()` / `setSelectedFiles(File[])`
|
||||||
|
* `getFileSelectionMode()` / `setFileSelectionMode(int)` : FILES_ONLY | DIRECTORIES_ONLY | FILES_AND_DIRECTORIES
|
||||||
|
* `isFileSelectionEnabled()` / `isDirectorySelectionEnabled()`
|
||||||
|
* `isMultiSelectionEnabled()` / `setMultiSelectionEnabled()`
|
||||||
|
* `isAcceptAllFileFilterUsed()` / `setAcceptAllFileFilterUsed(boolean)`
|
||||||
|
* `Dialog createDialog(Component)`
|
||||||
|
|
||||||
|
|
||||||
|
* `ensureFileIsVisible(File)`
|
||||||
|
* `getCurrentDirectory()` / `setCurrentDirectory(File)`
|
||||||
|
* `changeToParentDirectory()`
|
||||||
|
* `rescanCurrentDirectory()`
|
||||||
|
* `getDragEnabled()` / `setDragEnabled(boolean)`
|
||||||
|
|
||||||
|
|
||||||
|
* `getAccessory()` / `setAccessory(JComponent)`
|
||||||
|
* `getFileFilter()` / `setFileFilter(FileFilter)`
|
||||||
|
* `getChoosableFileFilters()` / `resetChoosableFileFilters()`
|
||||||
|
* `addChoosableFileFilter(FileFilter)` / `removeChoosableFileFilter(FileFilter)` / `getAcceptAllFileFilter()`
|
||||||
23
doc/06_combo_box.md
Normal file
23
doc/06_combo_box.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# 콤보 박스
|
||||||
|
|
||||||
|
* `JComboBox()` / `JComboBox(Object[])` / `JComboBox(ComboBoxModel)`
|
||||||
|
|
||||||
|
|
||||||
|
* `addItem(Object)` / `insertItemAt(Object,int)` : 항목을 동적으로 변경하려면, 콤보 박스의 데이터 모델이 MutableComboBoxModel이어야 한다.
|
||||||
|
* `getSelectedItem()` / `getItemAt(int)`
|
||||||
|
* `remoceItem(Object)` /`removeItemAt(int)` / `removeAllItems()` : 항목을 동적으로 변경하려면, 콤보 박스의 데이터 모델이 MutableComboBoxModel이어야 한다.
|
||||||
|
* `getItemCount()`
|
||||||
|
* `getModel()` / `setModel(ComboBoxModel)`
|
||||||
|
* `getAction()` / `setActionAction)`
|
||||||
|
|
||||||
|
|
||||||
|
* `addActionListener()`
|
||||||
|
* `addItemListener()`
|
||||||
|
|
||||||
|
|
||||||
|
* `isEditable()` / `setEditable(boolean)`
|
||||||
|
|
||||||
|
|
||||||
|
* `getRenderer()` / `setRenderer(ListCellRenderer)` : 아이템 뷰를 커스터마이징 할 때 사용한다. 콤보 박스가 editable 일 때에는 editor가 대신 사용된다.
|
||||||
|
* `getEditor()` / `setEditor(ComboBoxEditor)` : 콤보 박스가 editable 일 때 사용된다.
|
||||||
|
|
||||||
30
doc/07_dialog.md
Normal file
30
doc/07_dialog.md
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# 대화상자
|
||||||
|
|
||||||
|
|
||||||
|
## JOptionPane
|
||||||
|
* `void showMessageDialog()` : 부모 컴포넌트, 메시지, 타이틀, 메시지 타입, 아이콘
|
||||||
|
* `int showOptionDialog()` : 부모 컴포넌트, 메시지, 타이틀, 옵션 타입, 메시지 타입, 아이콘, 옵션 목록, 초기값
|
||||||
|
* `int showConfirmDialog()` : 부모 컴포넌트, 메시지, 타이틀, 옵션 타입, 메시지 타입, 아이콘
|
||||||
|
* `String showInputDialog()` : 부모 컴포넌트, 메시지, 타이틀, 메시지 타입, 아이콘, 옵션 목록, 초기값
|
||||||
|
* `showInternalMessageDialog()` / `showInternalXXXDialog()`
|
||||||
|
|
||||||
|
## JColorChooser
|
||||||
|
|
||||||
|
## JFileChooser
|
||||||
|
|
||||||
|
## JDialog
|
||||||
|
|
||||||
|
|
||||||
|
* `getContentPane()` / `setContentPane(Container)`
|
||||||
|
* `setLocationRelativeTo(Component)`
|
||||||
|
* `getDefaultCloseOption()` / `setDefaultCloseOption(int)` : DISPOSE_ON_CLOSE | DO_NOTHING_ON_CLOSE | HIDE_ON_CLOSE
|
||||||
|
* `isDefaultLookAndFeelDecorated()` / `setDefaultLookAndFeelDecorated(boolean)`
|
||||||
|
|
||||||
|
* `getModalityType()` / `setModalityType(Dialog.ModalityType)`
|
||||||
|
|
||||||
|
### ModalityType
|
||||||
|
* Modeless type
|
||||||
|
* Document-model type
|
||||||
|
* Application-modal type
|
||||||
|
* Toolkit-modal type
|
||||||
|
* Exclusion mode
|
||||||
55
doc/08_internal_frame.md
Normal file
55
doc/08_internal_frame.md
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
# Internal Frame
|
||||||
|
|
||||||
|
* `ststic int showInternalConfirmDialog()`
|
||||||
|
* `static String showInternalInputDialog()`
|
||||||
|
* `static Object showInternalMessageDialog()`
|
||||||
|
* `static int showInternalOptionDialog()`
|
||||||
|
|
||||||
|
|
||||||
|
* `getContentPane()` / `setContentPane(Container)`
|
||||||
|
* `getJMenuBar()` / `setJMenuBar()`
|
||||||
|
* `getLayeredPane()` / `setLayeredPane(JLayeredPane)`
|
||||||
|
|
||||||
|
* `setVisible(boolean)`
|
||||||
|
* `pack()`
|
||||||
|
* `setLocation(int,int)` / `setLocation(Point)`
|
||||||
|
* `setBounds(int,int,int,int)` / `setBounds(Rectangle)`
|
||||||
|
* `setSize(int,int)` / `setSize(Dimension)`
|
||||||
|
|
||||||
|
|
||||||
|
* `getDefaultCloseOperation()` / `setDefaultCloseOperation(int)` : DISPOSE_ON_CLOSE | DO_NOTHING_ON_CLOSE | HIDE_ON_CLOSE
|
||||||
|
* `addInternalFrameListener()` / `removeInternalFrameListener()`
|
||||||
|
* `moveToFront()` / `moveToBack()`
|
||||||
|
* `isClosed()` / `setClosed(boolean)`
|
||||||
|
* `isIcon()` / `setIcon(boolean)`
|
||||||
|
* `isMaximum()` / `setMaximum(boolean)`
|
||||||
|
* `isSelected()` / `setSelected(boolean)`
|
||||||
|
|
||||||
|
* `getFrameIcon()` / `setFrameIcon(Icon)`
|
||||||
|
* `isClosable()` / `setClosable(boolean)`
|
||||||
|
* `isIconifiable()` / `setIconifiable(boolean)`
|
||||||
|
* `isMaximizable()` / `setMaximizable(boolean)`
|
||||||
|
* `isResizable()` / `setResizable(boolean)`
|
||||||
|
* `getTitle()` / `setTitle(String)`
|
||||||
|
|
||||||
|
|
||||||
|
## JDesktopPane
|
||||||
|
|
||||||
|
* `getAllFrames()`
|
||||||
|
* `getAllFramesInLayer(int)`
|
||||||
|
* `getDragMode()` / `setDragMode(int)` : LIVE_DRAG_MODE | OUTLINE_DRAG_MODE
|
||||||
|
|
||||||
|
|
||||||
|
## JLayeredPane
|
||||||
|
|
||||||
|
* `jFrame.getLayeredPane()`
|
||||||
|
|
||||||
|
* `add(Component)` / `add(Component,Integer)` / `add(Component,Integer,int)` : 추가할 컴포넌트, 레이어, 레이어 내에서의 순서. 레이어가 지정되지 않으면 0번 레이어에 할당된다.
|
||||||
|
* `setLayer(Component,int)` / `setLayer(Component,int,int)` : 컴포넌트의 위치를 변경.
|
||||||
|
* `int getLayer(Component)`
|
||||||
|
* `getComponentCountInLayer(int)`
|
||||||
|
* `getComponentsInLayer(int)`
|
||||||
|
* `int lowestLayer()` / `int highestLayer()`
|
||||||
|
|
||||||
|
* `getPosition(Component)` / `setPosition(Component,int)`
|
||||||
|
* `moveToFront(Component)` / `moveToBack(Component)`
|
||||||
18
doc/09_label.md
Normal file
18
doc/09_label.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Label
|
||||||
|
|
||||||
|
* `getText()` / `setText(String)`
|
||||||
|
* `getIcon()` / `setIcon(Icon)`
|
||||||
|
* `getDisplayedMnemonic()` / `setDisplayedMnemonic(int)`
|
||||||
|
* `getDisplayedMnemonicIndex()` / `setDisplayedMnemonicIndex(int)`
|
||||||
|
* `getDisabledIcon()` / `setDisabledIcon(Icon)`
|
||||||
|
|
||||||
|
|
||||||
|
* `getVerticalAlignment()` / `setVerticalAlignment(int)` : TOP | CENTER | BOTTOM
|
||||||
|
* `getHorizontalAlignment()` / `setHorizontalAlignment(int)` : LEFT | CENTER | RIGHT | LEADING | TRAILING
|
||||||
|
* `getVerticalTextPosition()` / `setVerticalTextPosition(int)` : TOP | CENTER | BOTTOM
|
||||||
|
* `getHorizontalTextPosition()` / `setHorizontalTextPosition(int)` : LEFT | CENTER | RIGHT | LEADING | TRAILING
|
||||||
|
* `getIconTextGap()` / `setIconTextGap(int)`
|
||||||
|
|
||||||
|
* `getLabelFor()` / `setLabelFor(Component)`
|
||||||
|
|
||||||
|
|
||||||
23
doc/10_list.md
Normal file
23
doc/10_list.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# 리스트
|
||||||
|
|
||||||
|
* `getModel()` / `setModel(ListModel)`
|
||||||
|
* `setListData(Object[])` / `setListData(Vector)` : 데이터를 수정할 수 없다.
|
||||||
|
|
||||||
|
|
||||||
|
* `getLayoutOrientation()` / `setLayoutOrientation(int)` : VERTICAL | HORIZONTAL_WRAP | VERTICAL_WRAP
|
||||||
|
* `getVisobleRowCount()` / `setVisibleRowCount(int)`
|
||||||
|
* `getFirstVisibleIndex()` / `getLastVisibleIndex()`
|
||||||
|
* `ensureIndexIsVisible(int)`
|
||||||
|
|
||||||
|
|
||||||
|
* `getSelectionMode()` / `setSelectionMode(int)` : SINGLE_SELECTION | SINGLE_INTERVAL_SELECTION | MULTIPLE_INTERVAL_SELECTION
|
||||||
|
* `addListSelectionListener(ListSelectionListener)`
|
||||||
|
* `setSelectedIndex(int)` / `setSelectedIndices(int[])` / `setSelectedvalue(Object,int)` / `setSelectionInterval(int,int)`
|
||||||
|
* `getSelectedIndex()` / `getSelectedIndices()` / `getSelectedValue()` / `getSelectedValues()`
|
||||||
|
* `getMinSelectionIndex()` / `getMaxSelectionIndex()` / `getAnchorSelectionIndex()` / `getLeadSelectionIndex()`
|
||||||
|
* `isSelectionEmpty()` / `clearSelection()`
|
||||||
|
* `isSelectedIndex(int)`
|
||||||
|
|
||||||
|
* `setCellRenderer(ListCellRenderer)`
|
||||||
|
|
||||||
|
* `getDragEnabled()` / `setDragEnabled(boolean)`
|
||||||
43
doc/11_menu.md
Normal file
43
doc/11_menu.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# 메뉴
|
||||||
|
|
||||||
|
## JMenuBar
|
||||||
|
|
||||||
|
* `add(JMenu)`
|
||||||
|
* `jFrame.getJMenuBar()` / `jFrame.setJMenuBar(JMenuBar)`
|
||||||
|
|
||||||
|
|
||||||
|
## JMenu
|
||||||
|
|
||||||
|
* `JMenu()` / `JMenu(String)` / `JMenu(Action)`
|
||||||
|
|
||||||
|
* `add(JMenuItem)` / `add(String)` / `addSeparator()`
|
||||||
|
* `insert(JMenuItem,int)` / `insert(String,int)` / `insertSeparator(int)`
|
||||||
|
* `remove(JMenuItem)` / `remove(int)` / `removeAll()`
|
||||||
|
|
||||||
|
## JPopupMenu
|
||||||
|
|
||||||
|
* `add(JMenuItem)` / `add(String)` / `addSeparator()`
|
||||||
|
* `insert(JMenuItem,int)`
|
||||||
|
* `remove(int)` / `removeAll()`
|
||||||
|
* `setLightWeightPopupEnabled(boolean)`
|
||||||
|
* `show(Component,int,int)`
|
||||||
|
|
||||||
|
## JMenuItem
|
||||||
|
|
||||||
|
* `setEnabled(boolean)`
|
||||||
|
* `setMnemonic(int)` : KeyEvent.VK_...
|
||||||
|
* `setAccelerator(KeyStroke)`
|
||||||
|
* `setActionCommand(String)`
|
||||||
|
* `addActionListener()`
|
||||||
|
* `addItemListener()`
|
||||||
|
* `setAction(Action)`
|
||||||
|
|
||||||
|
|
||||||
|
## JCheckBoxMenuItem
|
||||||
|
|
||||||
|
* `getState()` / `setState(boolean)`
|
||||||
|
|
||||||
|
## JRadioButtonMenuItem
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
60
doc/12_panel.md
Normal file
60
doc/12_panel.md
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
# Panel
|
||||||
|
|
||||||
|
## JPanel
|
||||||
|
|
||||||
|
|
||||||
|
* `add(Component)` / `add(Component,int)` / `add(Component,Object)` / `add(Component,Object,int)` / `add(String,Component)`
|
||||||
|
* `getComponentCount()`
|
||||||
|
* `getComponent(int)` / `getComponentAt(int,int)` / `getComponentAt(Point)` / `getComponents()`
|
||||||
|
* `remove(Component)` / `remove(int)` / `removeAll()`
|
||||||
|
|
||||||
|
* `getLayout()` / `setLayout(LayoutManager)`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## JRootPane
|
||||||
|
* Glass pane
|
||||||
|
* Layered pane
|
||||||
|
* FRAME_CONTENT_LAYER : -30000
|
||||||
|
* DEFAULT_LAYER : 0
|
||||||
|
* PALETTE_LAYER : 100
|
||||||
|
* MODAL_LAYER : 200
|
||||||
|
* POPUP_LAYER : 300
|
||||||
|
* DRAG_LAYER : 400
|
||||||
|
* Content pane
|
||||||
|
* JMenu bar
|
||||||
|
|
||||||
|
|
||||||
|
* `jFrame.getRootPane()`
|
||||||
|
* `SwingUtilities.getRootPane(Component)`
|
||||||
|
* `jComponent.getRootPane()`
|
||||||
|
|
||||||
|
* `getDefaultButton()` / `setDefaultButton(JButton)`
|
||||||
|
|
||||||
|
* `jFrame.getGlassPane()` / `jFrame.setGlassPane(Component)`
|
||||||
|
* `jFrame.getLayeredPane()` / `jFrame.setLayeredPane(Component)`
|
||||||
|
* `jFrame.getContentPane()` / `jFrame.setContentPane(Container)`
|
||||||
|
* `jFrame.getJMenuBar()` / `jFrame.setJMenuBar(JMenuBar)`
|
||||||
|
|
||||||
|
|
||||||
|
## JScrollPane
|
||||||
|
|
||||||
|
* `JScrollPane(Component)` / `JScrollPane(Component,int,int)`
|
||||||
|
|
||||||
|
|
||||||
|
* `setviewportView(Component)`
|
||||||
|
* `getVerticalScrollBarPolicy()` / `setVerticalScrollBarPolicy(int)` : ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED | VERTICAL_SCROLLBAR_ALWAYS | VERTICAL_SCROLLBAR_NEVER
|
||||||
|
* `getHorizontalScrollBarPolicy()` / `setHorizontalScrollBarPolicy(int)` : ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED | HORIZONTAL_SCROLLBAR_ALWAYS | HORIZONTAL_SCROLLBAR_NEVER
|
||||||
|
* `getViewportBorder()` / `setViewportBorder(Border)`
|
||||||
|
* `isWheelScrollingEnabled()`
|
||||||
|
|
||||||
|
* `setRowHeaderView(Component)` / `setColumnHeaderView(Component)`
|
||||||
|
* `getCornet(String)` / `setCorner(String,Component)` : ScrollPaneConstants.UPPER_LEFT_CORNER | UPPER_RIGHT_CORNER | LOWER_LEFT_CORNER | LOWER_RIGHT_CORNER | LOWER_LEADING_CORNER | LOWER_TRAILING_CORNER | UPPER_LEADING_CORNER | UPPER_TRAILING_CORNER
|
||||||
|
|
||||||
|
### Scrollable
|
||||||
|
|
||||||
|
* `getScrollableUnitIncrement()` / `getScrollableBlockIncrement()`
|
||||||
|
* `getPreferredScrollableViewportSize()`
|
||||||
|
* `getScrollableTracksViewportWidth()` / `getScrollableTracksViewportHeight()`
|
||||||
|
|
||||||
39
doc/13_progress_bar.md
Normal file
39
doc/13_progress_bar.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# 프로그래스 바
|
||||||
|
|
||||||
|
## JProgressBar
|
||||||
|
|
||||||
|
* `JProgressBar()` / `JProgressBar(int)` / `JProgressBar(int,int)` / `JProgressBar(int,int,int)` : HORIZONTAL | VERTICAL, 최소값, 최대값
|
||||||
|
|
||||||
|
* `getValue()` / `setValue(int)`
|
||||||
|
* `double getPercentComplete()`
|
||||||
|
* `getMinimum()` / `setMinimum(int)`
|
||||||
|
* `getMaximum()` / `setMaximum(int)`
|
||||||
|
* `getModel()` / `setModel(BoundedRangeModel)`
|
||||||
|
|
||||||
|
|
||||||
|
* `getIndeterminated(boolean)`
|
||||||
|
* `getOrientation()` / `setOrientation(int)` : HORIZONTAL | VERTICAL
|
||||||
|
* `isBorderPainted()` / `setBorderPainted(boolean)`
|
||||||
|
* `isStringPainted()` / `setStringPainted(boolean)`
|
||||||
|
* `getString()` / `setString(String)`
|
||||||
|
|
||||||
|
|
||||||
|
## ProgressMonitor
|
||||||
|
|
||||||
|
진행률을 대화상자로 표시합니다. 특이하게도, 'J'로 시작하지 않네요.
|
||||||
|
|
||||||
|
* `ProgressMonitor(Component,Object,String,int,int)` : 부모 컴포넌트, 메시지, 노트, 최소값, 최대값
|
||||||
|
|
||||||
|
* `getMinimum()` / `setMinimum(int)`
|
||||||
|
* `getMaximum()` / `setMaximum(int)`
|
||||||
|
* `setProgress(int)`
|
||||||
|
* `getNote()` / `setNote(String)`
|
||||||
|
* `getMillisToDecideToPopup()` / `setMillisToDecideToPopup(int)`
|
||||||
|
|
||||||
|
* `close()`
|
||||||
|
* `isCanceled()`
|
||||||
|
|
||||||
|
## ProgressMonitorInputStream
|
||||||
|
|
||||||
|
* `getProgressMonitor()`
|
||||||
|
|
||||||
16
doc/14_separator.md
Normal file
16
doc/14_separator.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# Separator
|
||||||
|
|
||||||
|
* `jToolbar.addSeparator()` / `jToolbar.addSeparator(Dimension)`
|
||||||
|
* `jMenu.addSeparator()` / `jMenu.insertSeparator(int)`
|
||||||
|
* `jPopupMenu.addSeparator()`
|
||||||
|
|
||||||
|
|
||||||
|
* `JSeparator()` / `JSeparator(int)` : SwingConstants.HORIZONTAL | VERTICAL
|
||||||
|
* `getOrientation()` / `setOrientation(int)`
|
||||||
|
|
||||||
|
|
||||||
|
* `JToolBar.Separator()` | `JToolBar.Separator(Dimension)`
|
||||||
|
* `setSeparatorSize(Dimension()`
|
||||||
|
|
||||||
|
|
||||||
|
* `JPopupMenu.Separator()`
|
||||||
20
doc/15_slider.md
Normal file
20
doc/15_slider.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Slider
|
||||||
|
|
||||||
|
* `JSlider(int,int,int,int)` : 방향, 최소값, 최대값, 초기값
|
||||||
|
|
||||||
|
* `getValue()` / `setValue(int)`
|
||||||
|
* `getOrientation()` / `setOrientation(int)` : JSlider.HORIZONTAL | VERTICAL
|
||||||
|
* `getInverted()` / `setInverted(boolean)`
|
||||||
|
* `getMinimum()` / `setMinimum(int)` / `getMaximum()` / `setMaximum(int)`
|
||||||
|
* `getModel()` / `setModel(BoundedRangeModel)` : DefaultBoundedRangeModel implements BoundedRangeModel
|
||||||
|
* `getMajorTickSpacing()` / `setMajorTickSpacing(int)`
|
||||||
|
* `getMinorTickSpacing()` / `setMinorTickSpacing(int)`
|
||||||
|
* `getPaintTicks()` / `setPaintTicks(boolean)`
|
||||||
|
* `getPaintLabels()` / `setPaintLabels()`
|
||||||
|
* `getLabelTable()` / `setLabelTable(Dictionary)`
|
||||||
|
* `Hashtable createStandardLabels(int)` / `Hashtable createStandardLabels(int,int)`
|
||||||
|
* `setFont(Font)`
|
||||||
|
|
||||||
|
* `addChangeListener()`
|
||||||
|
* `boolean getValueIsAdjusting()`
|
||||||
|
|
||||||
42
doc/16_spinner.md
Normal file
42
doc/16_spinner.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Spinner
|
||||||
|
|
||||||
|
* `JSpinner()` / `JSpinner(SpinnerModel)`
|
||||||
|
|
||||||
|
* `getValue()` / `setValue(Object)`
|
||||||
|
* `getPreviousValue()` / `getNextValue()`
|
||||||
|
* `getModel()` / `setModel(SpinnerModel)`
|
||||||
|
* `getEditor()` / `setEditor(JComponent)`
|
||||||
|
* `protected JComponent createEditor(SpinnerModel)`
|
||||||
|
|
||||||
|
## SpinnerModel
|
||||||
|
|
||||||
|
### SpinnerListModel
|
||||||
|
|
||||||
|
* `getList()` / `setList(List)`
|
||||||
|
|
||||||
|
### SpinnerNumberModel
|
||||||
|
|
||||||
|
* `Number getNumber()` / `setValue(Object)`
|
||||||
|
* `getMinimum()` / `setMinimum(Comparable)`
|
||||||
|
* `getMaximum()` / `setMaximum(Comparable)`
|
||||||
|
* `getStepSize()` / `setStepSize(Number)`
|
||||||
|
|
||||||
|
### SpinnerDateModel
|
||||||
|
|
||||||
|
* `getDate()` / `getValue()` / `setValue(Object)`
|
||||||
|
* `getStart()` / `setStart(Comparable)`
|
||||||
|
* `getEnd()` / `setEnd(Comparable)`
|
||||||
|
* `getCalendarField()` / `setCalendarField(int)` : Calendar.ERA | YEAR | MONTH | WEEK_OF_YEAR | WEEK_OF_MONTH | DAY_OF_MONTH | DAY_OF_YEAR | DAY_OF_WEEK | DAY_OF_WEEK_IN_MONTH | AM_PM | HOUR_OF_DAY | MINUTE | SECOND | MILLISECOND
|
||||||
|
|
||||||
|
## JSpinner.DefaultEditor
|
||||||
|
|
||||||
|
* `JFormattedTextField getTextField()`
|
||||||
|
|
||||||
|
### JSpinner.ListEditor
|
||||||
|
### JSpinner.DateEditor
|
||||||
|
|
||||||
|
* `JSpinner.DateEditor(JSpinner,String)` : 포맷
|
||||||
|
|
||||||
|
### JSpinner.NumberEditor
|
||||||
|
|
||||||
|
* `JSpinner.NumberEditor(JSpinner,String)` : 포맷
|
||||||
16
doc/17_split_pane.md
Normal file
16
doc/17_split_pane.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# Split Pane
|
||||||
|
|
||||||
|
* `getOrientation()` / `setOrientation(int)` : HORIZONTAL_SPLIT | VERTICAL_SPLIT
|
||||||
|
* `getDividerSize()` / `setDividerSize(int)`
|
||||||
|
* `isContinuousLayout()` / `setContinuousLayout(boolean)` : 설정되면, 디바이더가 움직일때마다 화면을 다시 그린다.
|
||||||
|
* `isOneTouchExpandable()` / `setOneTouchExpandable(boolean)`
|
||||||
|
|
||||||
|
* `getLeftComponent()` / `getTopComponent()` / `setLeftComponent(component)` / `setTopComponent(Component)`
|
||||||
|
* `getRightComponent()` / `getBottomComponent()` / `setRightComponent(component)` / `setBottomComponent(Component)`
|
||||||
|
* `remove(Component)` / `removeAll()`
|
||||||
|
|
||||||
|
* `getDividerLocation()` / `setDividerLocation(int)` / `setDividerLocation(double)`
|
||||||
|
* `resetToPreferredSizes()`
|
||||||
|
* `getLastDividerLocation()` / `setLastDividerLocation(int)`
|
||||||
|
* `getMinimumDividerLocation()` / `getMaximumDividerLocation()`
|
||||||
|
* `getResizeWeight()` / `setResizeWeight(float)` : 0.0 ~ 1.0
|
||||||
29
doc/18_tabbed_pane.md
Normal file
29
doc/18_tabbed_pane.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Tabbed pane
|
||||||
|
|
||||||
|
* `JTabbedPane()` / `JTabbedPane(int)` / `JTabbedPane(int,int)` : TOP | BOTTOM | LEFT | RIGHT, WRAP_TAB_LAYOUT | SCROLL_TAB_LAYOUT
|
||||||
|
|
||||||
|
* `addTab(String,Icon,Component,String)` / `addTab(String,Icon,Component)` / `addTab(String,Component)` : 타이틀, 아이콘, 패널, 툴팁
|
||||||
|
* `insertTab(String,Icon,Component,String,int)`
|
||||||
|
* `removeTab(Component)` / `removeTabAt(int)` / `removeAll()`
|
||||||
|
* `getTabLayoutPolicy()` / `setTabLayoutPolicy(int)` : WRAP_TAB_LAYOUT | SCROLL_TAB_LAYOUT
|
||||||
|
* `getTabPlacement()` / `setTabPlacement(int)` : TOP | BOTTOM | LEFT | RIGHT
|
||||||
|
|
||||||
|
* `indexOfComponent(Component)` / `indexOfTab(String)` / `indexOfTab(Icon)`
|
||||||
|
* `getSelectedIndex()` / `setSelectedIndex(int)` / `getSelectedComponent()` / `setSelectedComponent(Component)`
|
||||||
|
|
||||||
|
|
||||||
|
* `getComponentAt()` / `setComponentAt(int,Component)`
|
||||||
|
* `getTitleAt(int)` / `setTitleAt(int,String)`
|
||||||
|
* `getIconAt(int)` / `setIconAt(int,Icon)`
|
||||||
|
* `getDisabledIconAt(int)` / `setDisabledIconAt(int,Icon)`
|
||||||
|
* `getBackgroundAt(int)` / `setBackgroundAt(int,Color)`
|
||||||
|
* `getForegroundAt(int)` / `setForegroundAt(int,Icon)`
|
||||||
|
* `isEnabledAt(int)` / `setEnabledAt(int,boolean)`
|
||||||
|
* `getMnemonicAt(int)` / `setMnemonicAt(int,int)`
|
||||||
|
* `getDisplayedMnemonicIndexAt(int)` / `setDisplayedMnemonicIndexAt(int,int)`
|
||||||
|
* `getToolTipTextAt(int)` / `setToolTipTextAt(int,String)`
|
||||||
|
|
||||||
|
* `getTabComponentAt(int)` / `setTabComponentAt(int,Component)`
|
||||||
|
* `indexOfTabComponent(Component)`
|
||||||
|
|
||||||
|
|
||||||
65
doc/19_table.md
Normal file
65
doc/19_table.md
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
# 테이블
|
||||||
|
|
||||||
|
## JTable
|
||||||
|
|
||||||
|
* `JTable(Object[][],Object[])` / `JTable(TableModel)`
|
||||||
|
|
||||||
|
|
||||||
|
* `setFillsViewportHeight(boolean)`
|
||||||
|
* `getTableModel()`
|
||||||
|
* `getTableHeader()`
|
||||||
|
* `getColumnModel()`
|
||||||
|
* `setAutoResizeMode(int)`
|
||||||
|
* `setSelectionMode(int)` : ListSelectionModel.MULTIPLE_INTERVAL_SELECTION | SINGLE_INTERVAL_SELECTION | SINGLE_SELECTION
|
||||||
|
* `getRowSelectionAllowed()` / `setRowSelectionAllowed(boolean)`
|
||||||
|
* `getColumnSelectionAllowed()` / `setColumnSelectionAllowed(boolean)`
|
||||||
|
* `getCellSelectionAllowed()` / `setCellSelectionAllowed(boolean)`
|
||||||
|
* `getSelectedRows()` / `getSelectedColumns()`
|
||||||
|
|
||||||
|
* `setDefaultRenderer()`
|
||||||
|
* `setDefaultEditor()`
|
||||||
|
|
||||||
|
* `setAutoCreateRowSorted(boolean)`
|
||||||
|
* `setRowSorted(TableRowSorter)`
|
||||||
|
|
||||||
|
|
||||||
|
## TableModel
|
||||||
|
|
||||||
|
* `addTableModelListener()`
|
||||||
|
* `fireTableCellUpdated()`
|
||||||
|
* `fireTableRowUpdated()`
|
||||||
|
* `fireTableDataChanged()`
|
||||||
|
* `fireTableRowsInserted()`
|
||||||
|
* `fireTableRowsDeleted()`
|
||||||
|
* `fireTableStructureChanged()`
|
||||||
|
|
||||||
|
### DefaultTableModel
|
||||||
|
|
||||||
|
### AbstractTableModel
|
||||||
|
|
||||||
|
## JTableHeader
|
||||||
|
|
||||||
|
## TableColumnModel
|
||||||
|
|
||||||
|
* `getColumn()`
|
||||||
|
|
||||||
|
## TableColumn
|
||||||
|
|
||||||
|
* `setPreferredWidth(int)`
|
||||||
|
* `setCellRenderer()`
|
||||||
|
* `setCellEditor()`
|
||||||
|
|
||||||
|
|
||||||
|
## TableModelListener
|
||||||
|
|
||||||
|
## TableCellRenderer
|
||||||
|
|
||||||
|
* `setToolTipText()`
|
||||||
|
|
||||||
|
### DefaultTableCellRenderer
|
||||||
|
|
||||||
|
## TableRowSorter
|
||||||
|
|
||||||
|
## TableCellEditor
|
||||||
|
### DefaultCellEditor
|
||||||
|
### AbstractCellEditor
|
||||||
10
doc/20_toolbar.md
Normal file
10
doc/20_toolbar.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# ToolBar
|
||||||
|
|
||||||
|
* `JToolBar()` / `JToolBar(int)` / `JToolBar(String)` / `JToolBar(String,int)` : 타이틀, 방향. HORIZONTAL | VERTICAL
|
||||||
|
|
||||||
|
* `add(Component)`
|
||||||
|
* `addSeparator()`
|
||||||
|
|
||||||
|
* `isFloatable()` / `setFloatable(boolean)`
|
||||||
|
* `isRollover()` / `setRollover(boolean)`
|
||||||
|
|
||||||
5
doc/21_tooltip.md
Normal file
5
doc/21_tooltip.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Tool tip
|
||||||
|
|
||||||
|
* `jComponent.getToolTipText()` / `jComponent.setToolTipText(String)`
|
||||||
|
* `jComponent.getToolTipText(MouseEvent)`
|
||||||
|
* `jComponent.getToolTipLocation(MouseEvent)`
|
||||||
54
doc/22_tree.md
Normal file
54
doc/22_tree.md
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
# Tree
|
||||||
|
|
||||||
|
|
||||||
|
## JTree
|
||||||
|
|
||||||
|
* `setCellRenderer(TreeCellRenderer)`
|
||||||
|
* `setCellEditor(TreeCellEditor)`
|
||||||
|
* `setEditable(boolean)`
|
||||||
|
* `setRootVisible(boolean)`
|
||||||
|
* `setShowsRootHandles(boolean)`
|
||||||
|
* `getDragEnabled()` / `setDragEnabled(boolean)`
|
||||||
|
|
||||||
|
* `addTreeSelectionListener()`
|
||||||
|
* `getSelectionModel()` / `setSelectionModel()` : TreeSelectionModel.CONTIGUOUS_TREE_SELECTION | DISCONTIGUOUS_TREE_SELECTION | SINGLE_TREE_SELECTION
|
||||||
|
* `getLastSelectedPathComponent()`
|
||||||
|
* `getSelectionPath()` / `setSelectionPath(TreePath)` / `getSelectionPaths()` / `setSelectionPaths(TreePath[])`
|
||||||
|
|
||||||
|
* `addTreeExpansionListener()`
|
||||||
|
* `addTreeWillExpandListener()`
|
||||||
|
* `expandPath(TreePath)`
|
||||||
|
* `collapsePath(TreePath)`
|
||||||
|
* `scrollPathToVisible(TreePath)`
|
||||||
|
* `makeVisible(TreePath)`
|
||||||
|
* `getScrollsOnExpand()` / `setScrollsOnExpand(boolean)`
|
||||||
|
* `getToggleClickCount()` / `setToggleClickCount(int)` : 기본값은 더블 클릭.
|
||||||
|
* `TreePath getNextMatch(String,int,Position.Bias)`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## TreePath
|
||||||
|
|
||||||
|
## TreeNode
|
||||||
|
### MutableTreeNode
|
||||||
|
### DefaultMutableTreeNode
|
||||||
|
|
||||||
|
## TreeModel
|
||||||
|
### DefaultTreeModel
|
||||||
|
|
||||||
|
## TreeCellRenderer
|
||||||
|
### DefaultTreeCellRenderer
|
||||||
|
|
||||||
|
## TreeCellEditor
|
||||||
|
### DefaultTreeCellEditor
|
||||||
|
|
||||||
|
## TreeSelectionListener
|
||||||
|
### TreeSelectionEvent
|
||||||
|
|
||||||
|
## TreeModelListener
|
||||||
|
### TreeModelEvent
|
||||||
|
|
||||||
|
## TreeExpansionListener
|
||||||
|
### TreeExpansionEvent
|
||||||
|
|
||||||
|
## TreeWillExpandListener
|
||||||
10
doc/23_icon.md
Normal file
10
doc/23_icon.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Icon
|
||||||
|
|
||||||
|
* `getImage()` / `setImage(Image)`
|
||||||
|
* `paintIcon(Component,Graphics,int,int)`
|
||||||
|
* `getDescription()` / `setDescription(String)`
|
||||||
|
* `getIconWidth()` / `getIconHeight()`
|
||||||
|
|
||||||
|
* `getImageObserver()` / `setImageObserver(ImageObserver)`
|
||||||
|
* `getImageLoadStatus()`
|
||||||
|
|
||||||
13
doc/24_border.md
Normal file
13
doc/24_border.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Border
|
||||||
|
|
||||||
|
* `BorderFactory.createLineBorder()`
|
||||||
|
* `BorderFactory.createEtchedBorder()`
|
||||||
|
* `BorderFactory.createLoweredBevelBorder()` / `BorderFactory.createRaisedBevelBorder()` / `BorderFactory.createBevelBorder()`
|
||||||
|
* `BorderFactory.createEmptyBorder()`
|
||||||
|
* `BorderFactory.createMatteBorder()`
|
||||||
|
* `BorderFactory.createTitledBorder()`
|
||||||
|
* `BorderFactory.createCompoundBorder()`
|
||||||
|
|
||||||
|
|
||||||
|
* `component.getBorder()` / `component.setBorder(Border)`
|
||||||
|
* `component.isBorderPainted()` / `component.setBorderPainted(boolean)`
|
||||||
45
doc/25_thread.md
Normal file
45
doc/25_thread.md
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
# Thread
|
||||||
|
|
||||||
|
```java
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
* `SwingUtilities.isEventDispatchThread()`
|
||||||
|
|
||||||
|
|
||||||
|
## Swing Worker
|
||||||
|
|
||||||
|
SwingWorker의 첫 번째 제너릭은 `doInBackground()`의 반환 타입입니다.
|
||||||
|
두 번째 제너릭은 `publish()`와 `process()`가 서로 주고 받는 데이터 타입입니다.
|
||||||
|
|
||||||
|
* **doInBackground()** : 백그라운드에서 작업을 처리합니다.
|
||||||
|
* **done()** : 백그라운드 작업이 끝난 직후에 이벤트 디스패치 스레드에서 실행됩니다.
|
||||||
|
* **publish()** : 백그라운드 작업 도중, 중간 결과를 내보냅니다. 이벤트 디스패치 스레드에서 **process()**가 호출됩니다.
|
||||||
|
|
||||||
|
|
||||||
|
* `get()` / `get(long,TimeUnit)`
|
||||||
|
* `setProgress()`
|
||||||
|
* `SwingWorker.StateValue getState()`
|
||||||
|
* `isCancelled()` / `isDone()`
|
||||||
|
|
||||||
|
|
||||||
|
## Swing Timer
|
||||||
|
|
||||||
|
타이머는 지연 시간 이후에 이벤트 디스패치 스레드에서 액션을 실행합니다.
|
||||||
|
|
||||||
|
```java
|
||||||
|
final Timer timer = new Timer(0, new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
timer.start();
|
||||||
|
```
|
||||||
|
|
||||||
|
* `getDelay()` / `setDelay(long)`
|
||||||
|
* `getInitialDelay()` / `setInitialDelay(long)`
|
||||||
|
* `isRepeats()` / `setRepeats(boolean)`
|
||||||
|
* `start()` / `restart()` / `stop()`
|
||||||
76
doc/26_desktop.md
Normal file
76
doc/26_desktop.md
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# Desktop
|
||||||
|
|
||||||
|
* `Desktop.isDesktopSupported()`
|
||||||
|
* `Desktop.getDesktop()`
|
||||||
|
* `isSupported(Desktop.Action)`
|
||||||
|
* `browse(URI)`
|
||||||
|
* `mail(URI)`
|
||||||
|
* `open(File)`
|
||||||
|
* `edit(File)`
|
||||||
|
* `print(File)`
|
||||||
|
|
||||||
|
## Desktop.Action
|
||||||
|
* BROWSE
|
||||||
|
* MAIL
|
||||||
|
* OPEN
|
||||||
|
* EDIT
|
||||||
|
* PRINT
|
||||||
|
|
||||||
|
# GraphicsEnvironment
|
||||||
|
|
||||||
|
* `GraphicsEnvironment.getLocalGraphicsEnvironment()`
|
||||||
|
* `GraphicsDevice getDefaultScreenDevice()`
|
||||||
|
|
||||||
|
# GraphicsDevice
|
||||||
|
|
||||||
|
* `isWindowTranslucencySupported()` : WindowTranslucency.TRANSLUCENT | PERPIXEL_TRANSLUCENT | PERPIXEL_TRANSPARENT
|
||||||
|
|
||||||
|
```java
|
||||||
|
jFrame.setOpacity(0.5f);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Splash Screen
|
||||||
|
|
||||||
|
* `SplashScreen.getSplashScreen()`
|
||||||
|
* `Graphics2D createGraphics()`
|
||||||
|
* `getBounds()`
|
||||||
|
* `close()`
|
||||||
|
|
||||||
|
|
||||||
|
```java
|
||||||
|
final SplashScreen splashScreen = SplashScreen.getSplashScreen();
|
||||||
|
Graphics2D graphics2D = splashScreen.createGraphics();
|
||||||
|
// ...
|
||||||
|
splashScreen.close();
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: <class name>
|
||||||
|
SplashScreen-Image: <image name>
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## System tray
|
||||||
|
|
||||||
|
* `SystemTray.isSupported()`
|
||||||
|
* `SystemTray.getSystemTray()`
|
||||||
|
* `add(TrayIcon)` / `remove(TrayIcon)`
|
||||||
|
|
||||||
|
|
||||||
|
```java
|
||||||
|
if(SystemTray.isSupported()){
|
||||||
|
SystemTray systemTray = SystemTray.getSystemTray();
|
||||||
|
systemTray.add(new TrayIcon(...));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
### TrayIcon
|
||||||
|
|
||||||
|
* `TrayIcon(Image,String,PopupMenu)`
|
||||||
|
|
||||||
|
* `setImage(Image)`
|
||||||
|
* `setImageAutoSize(boolean)`
|
||||||
|
* `setPopupMenu(PopupMenu)`
|
||||||
|
* `setToolTip(String)`
|
||||||
99
doc/27_layout_manager.md
Normal file
99
doc/27_layout_manager.md
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
# Layout Manager
|
||||||
|
|
||||||
|
* `component.setMinimumSize()` / `component.setMaximumSize()` / `component.setPreferredSize()`
|
||||||
|
|
||||||
|
## Border Layout
|
||||||
|
|
||||||
|
* PAGE_START
|
||||||
|
* PAGE_END
|
||||||
|
* LINE_START
|
||||||
|
* LINE_END
|
||||||
|
* CENTER
|
||||||
|
|
||||||
|
* `container.add(Component,BorderLayout.CENTER)`
|
||||||
|
* `setHGap(int)` / `setVGap(int)`
|
||||||
|
|
||||||
|
## Box Layout
|
||||||
|
|
||||||
|
* LINE_AXIS
|
||||||
|
* PAGE_AXIS
|
||||||
|
|
||||||
|
### Box.Filler
|
||||||
|
|
||||||
|
* `Box.createRigidArea()` : 컴포넌트 사이에 고정된 크기의 공간을 만들 때 사용합니다.
|
||||||
|
* `Box.createHorizontalGlue()` / `Box.createVerticalGlue()` : 컴포넌트 사이에 최대한의 빈 공간을 만들고자 할 때 사용합니다.
|
||||||
|
* `Box.createHorizontalStrut()` / `Box.createVerticalStrut()` : Strut보다는 RigidArea를 사용
|
||||||
|
* `new Box.Filler(Dimension,Dimension,Dimension)` : 최소, 희망, 최대 크기.
|
||||||
|
|
||||||
|
* `changeShape(Dimension,Dimension,Dimension)` : 레이아웃도 따라서 변경된다.
|
||||||
|
|
||||||
|
## Card Layout
|
||||||
|
|
||||||
|
* `container.add(Component,String)`
|
||||||
|
|
||||||
|
* `first(Container)` / `last(Container)`
|
||||||
|
* `next(Container)` / `previous(Container)`
|
||||||
|
* `show(Container,String)`
|
||||||
|
|
||||||
|
## Flow Layout
|
||||||
|
|
||||||
|
JPanel의 기본 레이아웃 매니저입니다.
|
||||||
|
|
||||||
|
* LEADING
|
||||||
|
* CENTER
|
||||||
|
* TRAILING
|
||||||
|
|
||||||
|
* `setHGap(int)` / `setVGap(int)`
|
||||||
|
* `setAlignment(int)` : FlowLayout.LEADING | CENTER | TRAILING
|
||||||
|
|
||||||
|
## Grid Bag Layout
|
||||||
|
|
||||||
|
* `add(Component,GridBagConstraints)`
|
||||||
|
|
||||||
|
### GridBagConstraints
|
||||||
|
* gridx, gridy : 컴포넌트가 위치할 열과 행의 좌표를 지정한다. RELATIVE를 지정하면 이전 컴포넌트의 오른쪽이나 아래에 놓는다.
|
||||||
|
* gridwidth, gridheight : 컴포넌트가 몇 칸을 차지할지를 지정한다. 기본 값은 1이다. 열이나 행의 마지막 컴퍼넌트에는 REMAINDER를 사용한다.
|
||||||
|
* fill : 컴포넌트 보다 큰 공간을 어떻게 채울지를 지정한다. NONE | HORIZONTAL | VERTICAL | BOTH
|
||||||
|
* ipadx, ipady : 컴포넌트 안쪽의 패딩 크기를 지정한다.
|
||||||
|
* insets : 컴포넌트 외부의 패딩 크기를 지정한다.
|
||||||
|
* anchor : CENTER | PAGE_START | PAGE_END | LINE_START | LINE_END | FIRST_LINE_START | FIRST_LINE_END | LAST_LINE_END | LAST_LINE_START
|
||||||
|
* weightx, weighty : 컴포넌트가 어느 정도의 크기를 가질지 가중치를 지정한다. 0 ~ 1사이의 값을 지정하며, 기본값은 0이다.
|
||||||
|
|
||||||
|
|
||||||
|
## Grid Layout
|
||||||
|
|
||||||
|
* `GridLayout(int,int)` : 열과 행의 크기를 지정한다.
|
||||||
|
|
||||||
|
## Group Layout
|
||||||
|
|
||||||
|
* Horizontal group / Vertical group
|
||||||
|
* Sequential group / Parallel group
|
||||||
|
|
||||||
|
* `addPreferredGap()` / `addContainerGap()` : RELATED | UNRELATED | INDENT
|
||||||
|
* `setAutoCreateGaps(boolean)` / `setAutoCreateContainerGaps(boolean)`
|
||||||
|
|
||||||
|
## Spring Layout
|
||||||
|
|
||||||
|
* NORTH
|
||||||
|
* SOUTH
|
||||||
|
* EAST
|
||||||
|
* WEST
|
||||||
|
* BASELINE
|
||||||
|
* HORIZONTAL_CENTER
|
||||||
|
* VERTICAL_CENTER
|
||||||
|
|
||||||
|
|
||||||
|
* `getConstraints(Component)`
|
||||||
|
* `Spring getConstraint(String,Component)`
|
||||||
|
* `putConstraint(String,Component,int,String,Component)` / `putConstraint(String,Component,Spring,String,Component)`
|
||||||
|
|
||||||
|
### SpringLayout.Constraints
|
||||||
|
|
||||||
|
* `getX()` / `getY()` / `getWidth()` / `getHeight()` / `setX()` / `setY()` / `setWidth()` / `setHeight()`
|
||||||
|
* `getConstraint(String)` / `setConstraint(String,Spring)`
|
||||||
|
|
||||||
|
### Spring
|
||||||
|
|
||||||
|
* `constant(int)` / `constant(int,int,int)`
|
||||||
|
* `Spring.sum(Spring,Spring)` / `Spring.max(Spring,Spring)` / `Spring.minus(Spring,Spring)`
|
||||||
|
* `getValue()` / `setValue(int)`
|
||||||
20
doc/28_look_and_feel.md
Normal file
20
doc/28_look_and_feel.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Look and Feel
|
||||||
|
|
||||||
|
```java
|
||||||
|
try {
|
||||||
|
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
||||||
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
|
||||||
|
UnsupportedLookAndFeelException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```java
|
||||||
|
// 프로그램 실행 후 룩앤필을 변경하는 경우
|
||||||
|
UIManager.setLookAndFeel(lnfName);
|
||||||
|
SwingUtilities.updateComponentTreeUI(frame);
|
||||||
|
frame.pack();
|
||||||
|
|
||||||
|
```
|
||||||
61
doc/29_drag_and_drop.md
Normal file
61
doc/29_drag_and_drop.md
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
# Drag & Drop
|
||||||
|
|
||||||
|
## TransferHandler
|
||||||
|
|
||||||
|
* `component.setDragEnabled(boolean)`
|
||||||
|
* `component.setDropMode(DropMode)`
|
||||||
|
* `component.setTransferHandler(TransferHandler)`
|
||||||
|
|
||||||
|
|
||||||
|
### 보내기
|
||||||
|
|
||||||
|
* `getSourceActions(JComponent)` : 보내는 컴포넌트가 어떤 액션을 지원하는지.
|
||||||
|
* `createTransferable(JComponent)` : 데이터를 묶어서 Transferable 객체로 만든다.
|
||||||
|
* `exportDone(JComponent,Transferable,int)` : 내보내기가 완료된 이후에 호출된다.
|
||||||
|
|
||||||
|
### 받기
|
||||||
|
|
||||||
|
* `canImport(Transferable.TransferSupport)` : 드래깅 동작 중 반복적으로 호출되며, 받는 컴퍼넌트가 드롭 동작을 지원하면 true를 반환한다.
|
||||||
|
* `importData(Transferable.TransferSupport)` : 드롭 동작 후에 호출되며, 데이터 전송이 성공한 경우에는 true를 반환한다.
|
||||||
|
|
||||||
|
|
||||||
|
## TransferSupport
|
||||||
|
|
||||||
|
* `getComponent()`
|
||||||
|
* `getDropAction()` : COPY | MOVE | LINK | COPY_OR_MOVE | NONE
|
||||||
|
* `getUserDropAction()`
|
||||||
|
* `getSourceDropActions()`
|
||||||
|
* `getDataFlavors()`
|
||||||
|
* `isDataFlavorSupported(DataFlavor)`
|
||||||
|
* `getTransferable()`
|
||||||
|
* `getDropLocation()`
|
||||||
|
|
||||||
|
* `setShowDropLocation(boolean)`
|
||||||
|
|
||||||
|
## DataFlavor
|
||||||
|
|
||||||
|
* allHtmlFlavor
|
||||||
|
* fragmentHtmlFlavor
|
||||||
|
* imageFlavor
|
||||||
|
* javFileListFlavor
|
||||||
|
* javaJVMLocaleObjectMimeType
|
||||||
|
* javaRemoteObjectMimeType
|
||||||
|
* javaSerializedObjectMimeType
|
||||||
|
* selectionHtmlFlavor
|
||||||
|
* stringFlavor
|
||||||
|
|
||||||
|
## DropLocation
|
||||||
|
* JList.DropLocation
|
||||||
|
* `isInsert()`
|
||||||
|
* `getIndex()`
|
||||||
|
* JTree.DropLocation
|
||||||
|
* `getChildIndex()`
|
||||||
|
* `getPath()`
|
||||||
|
* JTable.DropLocation
|
||||||
|
* `isInsertRow()`
|
||||||
|
* `isInserColumn()`
|
||||||
|
* `getRow()`
|
||||||
|
* `getColumn()`
|
||||||
|
* JTextComponent.DropLocation
|
||||||
|
* `getIndex()`
|
||||||
|
* `getBias()`
|
||||||
47
doc/30_listener.md
Normal file
47
doc/30_listener.md
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# Listeners
|
||||||
|
|
||||||
|
## ActionListener
|
||||||
|
|
||||||
|
## CaretListener
|
||||||
|
|
||||||
|
## ChangeListener
|
||||||
|
|
||||||
|
## ComponentListener
|
||||||
|
|
||||||
|
## ContainerListener
|
||||||
|
|
||||||
|
## DocumentListener
|
||||||
|
|
||||||
|
## FocusListener
|
||||||
|
|
||||||
|
## ItemListener
|
||||||
|
|
||||||
|
## KeyListener
|
||||||
|
|
||||||
|
## ListDataListener
|
||||||
|
|
||||||
|
## ListSelectionListener
|
||||||
|
|
||||||
|
## MouseListener
|
||||||
|
|
||||||
|
## MouseMotionListener
|
||||||
|
|
||||||
|
## MouseWheelListener
|
||||||
|
|
||||||
|
## PropertyChangeListener
|
||||||
|
|
||||||
|
## TableModelListener
|
||||||
|
|
||||||
|
## TreeExpansionListener
|
||||||
|
|
||||||
|
## TreeModelListener
|
||||||
|
|
||||||
|
## TreeSelectionListener
|
||||||
|
|
||||||
|
## TreeWillExpandListener
|
||||||
|
|
||||||
|
## UndoableEditListener
|
||||||
|
|
||||||
|
## WindowListener
|
||||||
|
|
||||||
|
## WindowStateListener
|
||||||
66
doc/31_painting.md
Normal file
66
doc/31_painting.md
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
# Painting
|
||||||
|
|
||||||
|
```java
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
final Graphics2D graphics2D = (Graphics2D) g;
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* `component.paint(Graphics)`
|
||||||
|
* `paintComponent(Graphics)` -> `paintBorder(Graphics)` -> `paintChildren(Graphics)`
|
||||||
|
|
||||||
|
|
||||||
|
## Graphics2D
|
||||||
|
|
||||||
|
|
||||||
|
* `drawString()`
|
||||||
|
* `drawImage()`
|
||||||
|
* `drawLine()`
|
||||||
|
* `drawArc()` / `drawRect()` / `drawOval()` / `drawPolygon()`
|
||||||
|
* `draw()`
|
||||||
|
* `fillArc()` / `fillRect()` / `fillOval()` / `fillPolygon()`
|
||||||
|
* `fill()`
|
||||||
|
|
||||||
|
* `rotate()`
|
||||||
|
* `scale()`
|
||||||
|
* `shear()`
|
||||||
|
* `translate()`
|
||||||
|
|
||||||
|
### Stroke
|
||||||
|
|
||||||
|
```java
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
Graphics2D graphics2D = (Graphics2D) g;
|
||||||
|
BasicStroke stroke = new BasicStroke(1.f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER,10.f,{10.f},0.f);
|
||||||
|
graphics2D.setStroke(stroke);
|
||||||
|
```
|
||||||
|
#### Join style
|
||||||
|
* JOIN_BEVEL
|
||||||
|
* JOIN_MITER
|
||||||
|
* JOIN_ROUND
|
||||||
|
|
||||||
|
#### End-cap style
|
||||||
|
* CAP_BUTT
|
||||||
|
* CAP_ROUND
|
||||||
|
* CAP_SQUARE
|
||||||
|
|
||||||
|
### Paint
|
||||||
|
* `Color`, `GradientPaint`, `TexturePaint`
|
||||||
|
|
||||||
|
```java
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
Paint paint = new GradientPaint(x1,y1,color1,x2,y2,color2);
|
||||||
|
graphics2D.setPaint(paint);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### AffineTransform
|
||||||
|
|
||||||
|
* `AffineTransform.getRotateTransform()`
|
||||||
|
* `AffineTransform.getScaleTransform()`
|
||||||
|
* `AffineTransform.getShearTransform()`
|
||||||
|
* `AffineTransform.getTranslateTransform()`
|
||||||
75
doc/32_geometric.md
Normal file
75
doc/32_geometric.md
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
# 도형
|
||||||
|
|
||||||
|
## Point
|
||||||
|
|
||||||
|
* Point2D.Double
|
||||||
|
* Point2D.Float
|
||||||
|
|
||||||
|
```java
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
|
Point2D point = new Point2D.Double(x, y);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Line
|
||||||
|
|
||||||
|
* Line2D.Double
|
||||||
|
* Line2D.Float
|
||||||
|
|
||||||
|
```java
|
||||||
|
import java.awt.geom.Line2D;
|
||||||
|
|
||||||
|
Line2D line = new Line2D.Double(point1, point2);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Curve
|
||||||
|
|
||||||
|
```java
|
||||||
|
import java.awt.geom.CubicCurve2D;
|
||||||
|
import java.awt.geom.QuadCurve2D;
|
||||||
|
|
||||||
|
QuadCurve2D quadCurve = new QuadCurve2D.Double(x1, y1, ctrlx, ctrly, x2, y2);
|
||||||
|
|
||||||
|
CubicCurve2D cubicCurve = new CubicCurve2D.Double(x1, y1, ctrlx1, ctrly1, ctrlx2,ctrly2,x2, y2);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Rectangle
|
||||||
|
|
||||||
|
```java
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.geom.RoundRectangle2D;
|
||||||
|
|
||||||
|
Rectangle2D rectangle = new Rectangle2D.Double(x, y, width, height);
|
||||||
|
|
||||||
|
RoundRectangle2D roundRectangle = new RoundRectangle2D.Double(x,y,width,height,archw,archy);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Ellipse
|
||||||
|
|
||||||
|
```java
|
||||||
|
import java.awt.geom.Ellipse2D;
|
||||||
|
|
||||||
|
Ellipse2D ellipse = new Ellipse2D.Double(x,y,width,height);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Arc
|
||||||
|
|
||||||
|
```java
|
||||||
|
import java.awt.geom.Arc2D;
|
||||||
|
|
||||||
|
Arc2D arc = new Arc2D.Double(x,y,width,height,start,extent,type);
|
||||||
|
```
|
||||||
|
|
||||||
|
## GeneralPath
|
||||||
|
|
||||||
|
* `moveTo(x,y)`
|
||||||
|
* `lineTo(x,y)`
|
||||||
|
* `quadTo(ctrlx,ctrly,x2,y2)`
|
||||||
|
* `curveTo(ctrlx1,ctrly1,ctrlx2,ctrly2,x2,y2)`
|
||||||
|
* `closePath()`
|
||||||
|
|
||||||
|
```java
|
||||||
|
import java.awt.geom.GeneralPath;
|
||||||
|
|
||||||
|
GeneralPath path = new GeneralPath();
|
||||||
|
```
|
||||||
31
doc/33_font.md
Normal file
31
doc/33_font.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Font
|
||||||
|
|
||||||
|
```java
|
||||||
|
Font font = Font.createFont(Font.TRUETYPE_FONT, new File("Abc.ttf"));
|
||||||
|
return font.deriveFont(12.f);
|
||||||
|
```
|
||||||
|
|
||||||
|
* `getFamily()`
|
||||||
|
* `getFontName()`
|
||||||
|
* `getAttributes()`
|
||||||
|
|
||||||
|
* `graphics2D.getFont()` / `graphics2D.setFont(Font)`
|
||||||
|
* `Font.createFont(int,InputStream)`
|
||||||
|
|
||||||
|
* `deriveFont()`
|
||||||
|
|
||||||
|
* `graphicsEnvironment.getAvailableFontFamilyNames()`
|
||||||
|
* `graphicsEnvironment.getAllFonts()`
|
||||||
|
|
||||||
|
```java
|
||||||
|
HashMap<TextAttribute,Object> map = new HashMap<>();
|
||||||
|
map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
|
||||||
|
font = font.deriveFont(map);
|
||||||
|
```
|
||||||
|
|
||||||
|
## FontMetrics
|
||||||
|
```java
|
||||||
|
FontMetrics fontMetrics = graphics2D.getFontMetrics(font);
|
||||||
|
int textHeight = fontMetrics.getHeight();
|
||||||
|
int textWidth = fontMetrics.stringWidth("Hello");
|
||||||
|
```
|
||||||
1
doc/35_editor_pane.md
Normal file
1
doc/35_editor_pane.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
https://docs.oracle.com/javase/tutorial/uiswing/components/editorpane.html
|
||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
rootProject.name = "tmpl-java-library"
|
rootProject.name = "swing-examples"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.elex_project.sample;
|
package com.elex_project.examples;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.BevelBorder;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class ComponentExample extends JPanel {
|
||||||
|
public ComponentExample() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
this.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
|
||||||
|
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||||
|
this.setBackground(Color.PINK);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new ComponentExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.CaretEvent;
|
||||||
|
import javax.swing.event.CaretListener;
|
||||||
|
import javax.swing.event.DocumentEvent;
|
||||||
|
import javax.swing.event.DocumentListener;
|
||||||
|
import javax.swing.text.Document;
|
||||||
|
import javax.swing.undo.UndoManager;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
|
public class DocumentListenerExample extends JPanel {
|
||||||
|
|
||||||
|
DocumentListenerExample() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
// UndoableEditListener
|
||||||
|
// 레이아웃 구성
|
||||||
|
final JToolBar toolBar = new JToolBar();
|
||||||
|
final JTextArea textArea = new JTextArea();
|
||||||
|
this.add(toolBar, BorderLayout.NORTH);
|
||||||
|
this.add(textArea, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
// 언두 매니저를 생성하고, 텍스트 문서에 리스너를 통해 연결한다.
|
||||||
|
final UndoManager undoManager = new UndoManager();
|
||||||
|
textArea.getDocument().addUndoableEditListener(undoableEditEvent ->
|
||||||
|
undoManager.addEdit(undoableEditEvent.getEdit()));
|
||||||
|
|
||||||
|
// 버튼을 통해서 액션을 처리한다.
|
||||||
|
toolBar.add(new AbstractAction("Undo") {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
if (undoManager.canUndo()) {
|
||||||
|
undoManager.undo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
toolBar.add(new AbstractAction("Redo") {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
if (undoManager.canRedo()) {
|
||||||
|
undoManager.redo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// DocumentListener
|
||||||
|
textArea.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
|
@Override
|
||||||
|
public void insertUpdate(DocumentEvent documentEvent) {
|
||||||
|
Document document = documentEvent.getDocument();
|
||||||
|
int changeLength = documentEvent.getLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeUpdate(DocumentEvent documentEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changedUpdate(DocumentEvent documentEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// CaretListener
|
||||||
|
textArea.addCaretListener(new CaretListener() {
|
||||||
|
@Override
|
||||||
|
public void caretUpdate(CaretEvent caretEvent) {
|
||||||
|
int dot = caretEvent.getDot();
|
||||||
|
int mark = caretEvent.getMark();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new DocumentListenerExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> jFrame.setVisible(true));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.button;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
public class ActionExample extends JPanel {
|
||||||
|
private static class Action1 extends AbstractAction {
|
||||||
|
Action1() {
|
||||||
|
super();
|
||||||
|
putValue(NAME, "Button 1");
|
||||||
|
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
System.out.println("Hello");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionExample() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
|
||||||
|
final JButton button1 = new JButton(new Action1());
|
||||||
|
|
||||||
|
|
||||||
|
// 레이아웃에 추가
|
||||||
|
add(button1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new ActionExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.button;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.BevelBorder;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
public class ButtonExample extends JPanel {
|
||||||
|
public ButtonExample() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
final JButton button1 = new JButton("Button 1", new DummyIcon());
|
||||||
|
button1.setMnemonic(KeyEvent.VK_A);// Alt와 함께 누른다.
|
||||||
|
button1.setActionCommand("disable");
|
||||||
|
|
||||||
|
final JButton button2 = new JButton("Button 2", new DummyIcon());
|
||||||
|
button2.setMnemonic(KeyEvent.VK_B);
|
||||||
|
button2.setActionCommand("delete");
|
||||||
|
|
||||||
|
// 레이아웃에 추가
|
||||||
|
add(button1);
|
||||||
|
add(button2);
|
||||||
|
|
||||||
|
// 액션 리스너를 통해서 클릭 이벤트를 받는다.
|
||||||
|
final ActionListener actionListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
switch (actionEvent.getActionCommand()){
|
||||||
|
case "disable":
|
||||||
|
System.out.println("disable");
|
||||||
|
break;
|
||||||
|
case "delete":
|
||||||
|
System.out.println("delete");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("oops!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
button1.addActionListener(actionListener);
|
||||||
|
button2.addActionListener(actionListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new ButtonExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyIcon implements Icon{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintIcon(Component component, Graphics graphics, int x, int y) {
|
||||||
|
graphics.setColor(Color.DARK_GRAY);
|
||||||
|
graphics.fillRect(x,y,x+getIconWidth(),y+getIconHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconWidth() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconHeight() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.button;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
|
||||||
|
public class CheckBoxExample extends JPanel {
|
||||||
|
public CheckBoxExample() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
final JCheckBox checkBox1 = new JCheckBox("Button 1");
|
||||||
|
checkBox1.setMnemonic(KeyEvent.VK_A);// Alt와 함께 누른다.
|
||||||
|
checkBox1.setSelected(true);
|
||||||
|
|
||||||
|
final JCheckBox checkBox2 = new JCheckBox("Button 2");
|
||||||
|
checkBox2.setMnemonic(KeyEvent.VK_B);
|
||||||
|
|
||||||
|
// 레이아웃에 추가한다.
|
||||||
|
add(checkBox1);
|
||||||
|
add(checkBox2);
|
||||||
|
|
||||||
|
// 아이템 리스너를 통해서 이벤트를 받는다.
|
||||||
|
final ItemListener itemListener = new ItemListener() {
|
||||||
|
@Override
|
||||||
|
public void itemStateChanged(ItemEvent itemEvent) {
|
||||||
|
ItemSelectable source = itemEvent.getItemSelectable();
|
||||||
|
if(source==checkBox1){
|
||||||
|
System.out.println(checkBox1.getText() + " is "
|
||||||
|
+ (checkBox1.isSelected()?"selected.":"not selected."));
|
||||||
|
} else if (source==checkBox2) {
|
||||||
|
System.out.println(checkBox2.getText() + " is "
|
||||||
|
+ (checkBox2.isSelected()?"selected.":"not selected."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
checkBox1.addItemListener(itemListener);
|
||||||
|
checkBox2.addItemListener(itemListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new CheckBoxExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.button;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
public class KeyBindingExample extends JPanel {
|
||||||
|
|
||||||
|
|
||||||
|
public KeyBindingExample() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, KeyEvent.CTRL_DOWN_MASK), "action1");
|
||||||
|
this.getActionMap().put("action1", new AbstractAction() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
System.out.println("action 1");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new KeyBindingExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.button;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
public class RadioButtonExample extends JPanel {
|
||||||
|
public RadioButtonExample() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
final JRadioButton radioButton1 = new JRadioButton("Button 1");
|
||||||
|
radioButton1.setMnemonic(KeyEvent.VK_A);// Alt와 함께 누른다.
|
||||||
|
radioButton1.setActionCommand("btn1");
|
||||||
|
radioButton1.setSelected(true);
|
||||||
|
|
||||||
|
final JRadioButton radioButton2 = new JRadioButton("Button 2");
|
||||||
|
radioButton2.setMnemonic(KeyEvent.VK_B);
|
||||||
|
radioButton2.setActionCommand("btn2");
|
||||||
|
|
||||||
|
// 레이아웃에 라디오 버튼을 추가
|
||||||
|
add(radioButton1);
|
||||||
|
add(radioButton2);
|
||||||
|
|
||||||
|
// 버튼에 액션 리스너를 연결한다.
|
||||||
|
final ActionListener actionListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
switch (actionEvent.getActionCommand()){
|
||||||
|
case "btn1":
|
||||||
|
System.out.println("btn1 is selected.");
|
||||||
|
break;
|
||||||
|
case "btn2":
|
||||||
|
System.out.println("btn2 is selected.");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("oops!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
radioButton1.addActionListener(actionListener);
|
||||||
|
radioButton2.addActionListener(actionListener);
|
||||||
|
|
||||||
|
// 라디오 버튼을 그룹으로 묶어준다.
|
||||||
|
final ButtonGroup group = new ButtonGroup();
|
||||||
|
group.add(radioButton1);
|
||||||
|
group.add(radioButton2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new RadioButtonExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.button;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ItemEvent;
|
||||||
|
import java.awt.event.ItemListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
public class ToggleButtonExample extends JPanel {
|
||||||
|
public ToggleButtonExample() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
final JToggleButton button1 = new JToggleButton("Button 1");
|
||||||
|
button1.setMnemonic(KeyEvent.VK_A);
|
||||||
|
button1.setSelected(true);
|
||||||
|
|
||||||
|
final JToggleButton button2 = new JToggleButton("Button 2");
|
||||||
|
button2.setMnemonic(KeyEvent.VK_B);
|
||||||
|
|
||||||
|
// 레이아웃에 추가한다.
|
||||||
|
add(button1);
|
||||||
|
add(button2);
|
||||||
|
|
||||||
|
// 아이템 리스너를 통해서 이벤트를 받는다.
|
||||||
|
final ItemListener itemListener = new ItemListener() {
|
||||||
|
@Override
|
||||||
|
public void itemStateChanged(ItemEvent itemEvent) {
|
||||||
|
ItemSelectable source = itemEvent.getItemSelectable();
|
||||||
|
if(source==button1){
|
||||||
|
System.out.println(button1.getText() + " is "
|
||||||
|
+ (button1.isSelected()?"selected.":"not selected."));
|
||||||
|
} else if (source==button2) {
|
||||||
|
System.out.println(button2.getText() + " is "
|
||||||
|
+ (button2.isSelected()?"selected.":"not selected."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
button1.addItemListener(itemListener);
|
||||||
|
button2.addItemListener(itemListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new ToggleButtonExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.chooser;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class ColorChooser2Example extends JPanel {
|
||||||
|
public ColorChooser2Example() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
final JLabel label = new JLabel("Welcome", JLabel.CENTER);
|
||||||
|
label.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
|
||||||
|
final JButton button = new JButton("Open Color Chooser...");
|
||||||
|
|
||||||
|
// 버튼을 클릭하면 대화상자를 띄운다.
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
Color color = JColorChooser
|
||||||
|
.showDialog(ColorChooser2Example.this,
|
||||||
|
"Color Dialog", label.getForeground());
|
||||||
|
if (null != color) {
|
||||||
|
label.setForeground(color);
|
||||||
|
} else {
|
||||||
|
System.out.println("color is null.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 레이아웃에 추가
|
||||||
|
add(label, BorderLayout.NORTH);
|
||||||
|
add(button, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new ColorChooser2Example());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyIcon implements Icon {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintIcon(Component component, Graphics graphics, int x, int y) {
|
||||||
|
graphics.setColor(Color.DARK_GRAY);
|
||||||
|
graphics.fillRect(x, y, x + getIconWidth(), y + getIconHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconWidth() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconHeight() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.chooser;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.colorchooser.AbstractColorChooserPanel;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class ColorChooser3Example extends JPanel {
|
||||||
|
public ColorChooser3Example() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
final JLabel label = new JLabel("Welcome", JLabel.CENTER);
|
||||||
|
label.setBorder(BorderFactory.createEmptyBorder(8,8,8,8));
|
||||||
|
final JColorChooser colorChooser = new JColorChooser(label.getForeground());
|
||||||
|
|
||||||
|
colorChooser.setPreviewPanel(new JPanel());
|
||||||
|
|
||||||
|
AbstractColorChooserPanel[] panels = {new AbstractColorChooserPanel() {
|
||||||
|
@Override
|
||||||
|
public void updateChooser() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void buildChooser() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDisplayName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Icon getSmallDisplayIcon() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Icon getLargeDisplayIcon() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
colorChooser.setChooserPanels(panels);
|
||||||
|
|
||||||
|
// 레이아웃에 추가
|
||||||
|
add(label, BorderLayout.NORTH);
|
||||||
|
add(colorChooser, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
// ChangeListener를 통해서 변경된 색상을 받는다.
|
||||||
|
colorChooser.getSelectionModel().addChangeListener(new ChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void stateChanged(ChangeEvent changeEvent) {
|
||||||
|
Color color = colorChooser.getColor();
|
||||||
|
label.setForeground(color);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new ColorChooser3Example());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyIcon implements Icon{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintIcon(Component component, Graphics graphics, int x, int y) {
|
||||||
|
graphics.setColor(Color.DARK_GRAY);
|
||||||
|
graphics.fillRect(x,y,x+getIconWidth(),y+getIconHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconWidth() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconHeight() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.chooser;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class ColorChooserExample extends JPanel {
|
||||||
|
public ColorChooserExample() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
final JLabel label = new JLabel("Welcome", JLabel.CENTER);
|
||||||
|
label.setBorder(BorderFactory.createEmptyBorder(8,8,8,8));
|
||||||
|
final JColorChooser colorChooser = new JColorChooser(label.getForeground());
|
||||||
|
|
||||||
|
// 레이아웃에 추가
|
||||||
|
add(label, BorderLayout.NORTH);
|
||||||
|
add(colorChooser, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
// ChangeListener를 통해서 변경된 색상을 받는다.
|
||||||
|
colorChooser.getSelectionModel().addChangeListener(new ChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void stateChanged(ChangeEvent changeEvent) {
|
||||||
|
Color color = colorChooser.getColor();
|
||||||
|
label.setForeground(color);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new ColorChooserExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyIcon implements Icon{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintIcon(Component component, Graphics graphics, int x, int y) {
|
||||||
|
graphics.setColor(Color.DARK_GRAY);
|
||||||
|
graphics.fillRect(x,y,x+getIconWidth(),y+getIconHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconWidth() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconHeight() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.chooser;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
public class FileChooserExample extends JPanel {
|
||||||
|
public FileChooserExample() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
final JToolBar toolBar = new JToolBar();
|
||||||
|
final JButton btnOpen = new JButton("Open");
|
||||||
|
final JButton btnSave = new JButton("Save");
|
||||||
|
toolBar.add(btnOpen);
|
||||||
|
toolBar.add(btnSave);
|
||||||
|
|
||||||
|
final JTextArea textArea = new JTextArea();
|
||||||
|
|
||||||
|
// 레이아웃에 추가
|
||||||
|
add(toolBar, BorderLayout.NORTH);
|
||||||
|
add(new JScrollPane(textArea), BorderLayout.CENTER);
|
||||||
|
|
||||||
|
final ActionListener actionListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
final JFileChooser fileChooser = new JFileChooser();
|
||||||
|
fileChooser.setFileFilter(new FileNameExtensionFilter("Text File", "txt"));
|
||||||
|
if (btnOpen == actionEvent.getSource()) {
|
||||||
|
int response = fileChooser.showOpenDialog(FileChooserExample.this);
|
||||||
|
if (response==JFileChooser.APPROVE_OPTION){
|
||||||
|
File file = fileChooser.getSelectedFile();
|
||||||
|
try {
|
||||||
|
String text = Files.readString(file.toPath());
|
||||||
|
textArea.setText(text);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (btnSave == actionEvent.getSource()) {
|
||||||
|
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||||
|
int response = fileChooser.showSaveDialog(FileChooserExample.this);
|
||||||
|
if (response==JFileChooser.APPROVE_OPTION){
|
||||||
|
File file = fileChooser.getSelectedFile();
|
||||||
|
try {
|
||||||
|
Files.writeString(new File(file, "test.txt").toPath(), textArea.getText());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
btnOpen.addActionListener(actionListener);
|
||||||
|
btnSave.addActionListener(actionListener);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new FileChooserExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyIcon implements Icon {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintIcon(Component component, Graphics graphics, int x, int y) {
|
||||||
|
graphics.setColor(Color.DARK_GRAY);
|
||||||
|
graphics.fillRect(x, y, x + getIconWidth(), y + getIconHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconWidth() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconHeight() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.combobox;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
public class ComboBoxExample extends JPanel {
|
||||||
|
public ComboBoxExample() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
final String[] options = {"A", "B", "C", "D"};
|
||||||
|
final JComboBox<String> comboBox = new JComboBox<>(options);
|
||||||
|
comboBox.setSelectedIndex(2);
|
||||||
|
|
||||||
|
// 액션 리스너를 통해서 이벤트를 받는다.
|
||||||
|
comboBox.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
JComboBox<String> component = (JComboBox<String>) actionEvent.getSource();
|
||||||
|
String selectedItem = (String) component.getSelectedItem();
|
||||||
|
System.out.println(selectedItem);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 레이아웃에 추가
|
||||||
|
add(comboBox);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new ComboBoxExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyIcon implements Icon{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintIcon(Component component, Graphics graphics, int x, int y) {
|
||||||
|
graphics.setColor(Color.DARK_GRAY);
|
||||||
|
graphics.fillRect(x,y,x+getIconWidth(),y+getIconHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconWidth() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconHeight() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.combobox;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class ComboBoxRendererExample extends JPanel {
|
||||||
|
public enum Item {
|
||||||
|
A, B, C, D;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MyRenderer extends JPanel implements ListCellRenderer<Item> {
|
||||||
|
private JLabel label;
|
||||||
|
|
||||||
|
MyRenderer() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
label = new JLabel();
|
||||||
|
setOpaque(true);
|
||||||
|
|
||||||
|
add(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getListCellRendererComponent(JList<? extends Item> jList, Item item, int index,
|
||||||
|
boolean isSelected, boolean hasFocus) {
|
||||||
|
|
||||||
|
// 선택된 항목의 색상을 변경해주고,
|
||||||
|
if (isSelected) {
|
||||||
|
setBackground(jList.getSelectionBackground());
|
||||||
|
setForeground(jList.getSelectionForeground());
|
||||||
|
} else {
|
||||||
|
setBackground(jList.getBackground());
|
||||||
|
setForeground(jList.getForeground());
|
||||||
|
}
|
||||||
|
// 선택된 항목의 값을 할당해 준다.
|
||||||
|
label.setText(item.name());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComboBoxRendererExample() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
final JComboBox<Item> comboBox = new JComboBox<>(Item.values());
|
||||||
|
comboBox.setRenderer(new MyRenderer());
|
||||||
|
comboBox.setMaximumRowCount(3);
|
||||||
|
|
||||||
|
// 액션 리스너를 통해서 이벤트를 받는다.
|
||||||
|
comboBox.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
JComboBox<Item> component = (JComboBox<Item>) actionEvent.getSource();
|
||||||
|
Item selectedItem = (Item) component.getSelectedItem();
|
||||||
|
System.out.println(selectedItem);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 레이아웃에 추가
|
||||||
|
add(comboBox);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new ComboBoxRendererExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyIcon implements Icon {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintIcon(Component component, Graphics graphics, int x, int y) {
|
||||||
|
graphics.setColor(Color.DARK_GRAY);
|
||||||
|
graphics.fillRect(x, y, x + getIconWidth(), y + getIconHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconWidth() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconHeight() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.combobox;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class EditableComboBoxExample extends JPanel {
|
||||||
|
public EditableComboBoxExample() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
final String[] options = {"A", "B", "C", "D"};
|
||||||
|
final JComboBox<String> comboBox = new JComboBox<>(options);
|
||||||
|
comboBox.setEditable(true);
|
||||||
|
comboBox.setSelectedIndex(2);
|
||||||
|
|
||||||
|
// 액션 리스너를 통해서 이벤트를 받는다.
|
||||||
|
comboBox.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
JComboBox<String> component = (JComboBox<String>) actionEvent.getSource();
|
||||||
|
String selectedItem = (String) component.getSelectedItem();
|
||||||
|
System.out.println(selectedItem);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 레이아웃에 추가
|
||||||
|
add(comboBox);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new EditableComboBoxExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyIcon implements Icon{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintIcon(Component component, Graphics graphics, int x, int y) {
|
||||||
|
graphics.setColor(Color.DARK_GRAY);
|
||||||
|
graphics.fillRect(x,y,x+getIconWidth(),y+getIconHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconWidth() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconHeight() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.label;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.BevelBorder;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class LabelExample extends JPanel {
|
||||||
|
public LabelExample() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
final ImageIcon icon = new ImageIcon(Objects.requireNonNull(LabelExample.class.getResource("/icon.png")));
|
||||||
|
|
||||||
|
final JLabel label = new JLabel("I'm a label.", icon, SwingConstants.CENTER);
|
||||||
|
label.setHorizontalAlignment(JLabel.CENTER);
|
||||||
|
label.setVerticalAlignment(JLabel.BOTTOM);
|
||||||
|
label.setOpaque(true);// 배경색을 지정하려면 불투명으로 변경해야 한다.
|
||||||
|
label.setBackground(Color.PINK);
|
||||||
|
|
||||||
|
final JTextField textField = new JTextField();
|
||||||
|
label.setLabelFor(textField);
|
||||||
|
|
||||||
|
this.add(label);
|
||||||
|
this.add(textField);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DummyIcon implements Icon {
|
||||||
|
private int width = 16;
|
||||||
|
private int height = 16;
|
||||||
|
@Override
|
||||||
|
public void paintIcon(Component component, Graphics graphics, int x, int y) {
|
||||||
|
Graphics2D g2d = (Graphics2D) graphics.create();
|
||||||
|
|
||||||
|
g2d.setColor(Color.WHITE);
|
||||||
|
g2d.fillRect(x +1 ,y + 1,width -2 ,height -2);
|
||||||
|
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g2d.drawRect(x +1 ,y + 1,width -2 ,height -2);
|
||||||
|
|
||||||
|
g2d.setColor(Color.RED);
|
||||||
|
|
||||||
|
g2d.setStroke(new BasicStroke(4));
|
||||||
|
g2d.drawLine(x +10, y + 10, x + width -10, y + height -10);
|
||||||
|
g2d.drawLine(x +10, y + height -10, x + width -10, y + 10);
|
||||||
|
|
||||||
|
g2d.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new LabelExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.list;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.ListSelectionEvent;
|
||||||
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class ListExample extends JPanel {
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
public static class Person {
|
||||||
|
private String firstName, lastName;
|
||||||
|
private int age;
|
||||||
|
private String address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PersonRenderer extends JPanel implements ListCellRenderer<Person> {
|
||||||
|
private final JLabel lblName;
|
||||||
|
private final JLabel lblAddress;
|
||||||
|
|
||||||
|
PersonRenderer() {
|
||||||
|
super();
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
lblName = new JLabel();
|
||||||
|
lblAddress = new JLabel();
|
||||||
|
|
||||||
|
add(lblName, BorderLayout.NORTH);
|
||||||
|
add(lblAddress, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
lblName.setFont(lblName.getFont().deriveFont(Font.BOLD));
|
||||||
|
setBorder(BorderFactory.createEmptyBorder(8,8,8,8));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getListCellRendererComponent(JList<? extends Person> jList, Person item, int index,
|
||||||
|
boolean isSelected, boolean hasFocus) {
|
||||||
|
// 선택된 항목의 색상을 변경해주고,
|
||||||
|
if (isSelected) {
|
||||||
|
setBackground(jList.getSelectionBackground());
|
||||||
|
setForeground(jList.getSelectionForeground());
|
||||||
|
} else {
|
||||||
|
setBackground(jList.getBackground());
|
||||||
|
setForeground(jList.getForeground());
|
||||||
|
}
|
||||||
|
// 선택된 항목의 값을 할당해 준다.
|
||||||
|
lblAddress.setText(item.getAddress());
|
||||||
|
lblName.setText(item.getFirstName() + " " + item.getLastName());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListExample() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
final DefaultListModel<Person> listModel = new DefaultListModel<>();
|
||||||
|
listModel.addElement(new Person("Charlie", "Brown", 13, "Snoopy house"));
|
||||||
|
listModel.addElement(new Person("Steve", "McQueen", 24, "Garage"));
|
||||||
|
|
||||||
|
|
||||||
|
final JList<Person> jList = new JList<>(listModel);
|
||||||
|
jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
|
jList.setLayoutOrientation(JList.VERTICAL);
|
||||||
|
jList.setVisibleRowCount(-1);
|
||||||
|
jList.setCellRenderer(new PersonRenderer());
|
||||||
|
jList.addListSelectionListener(new ListSelectionListener() {
|
||||||
|
@Override
|
||||||
|
public void valueChanged(ListSelectionEvent listSelectionEvent) {
|
||||||
|
if (!listSelectionEvent.getValueIsAdjusting()) {
|
||||||
|
System.out.println(jList.getSelectedValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
final JButton addButton = new JButton("Add");
|
||||||
|
addButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
int index = jList.getSelectedIndex();
|
||||||
|
if (index == -1) index = 0;
|
||||||
|
else index++;
|
||||||
|
listModel.insertElementAt(
|
||||||
|
new Person("Soohanmoo", "Kim", 543, "Unknown"), index);
|
||||||
|
|
||||||
|
jList.setSelectedIndex(index);
|
||||||
|
jList.ensureIndexIsVisible(index);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.add(new JScrollPane(jList), BorderLayout.CENTER);
|
||||||
|
this.add(addButton, BorderLayout.NORTH);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new ListExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.progress;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
|
||||||
|
public class ProgressBarExample extends JPanel {
|
||||||
|
final JProgressBar progressBar;
|
||||||
|
|
||||||
|
public ProgressBarExample() {
|
||||||
|
super();
|
||||||
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
|
||||||
|
|
||||||
|
final JButton button = new JButton("Start");
|
||||||
|
progressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100);
|
||||||
|
progressBar.setIndeterminate(false);
|
||||||
|
progressBar.setStringPainted(true);
|
||||||
|
|
||||||
|
this.add(button);
|
||||||
|
this.add(progressBar);
|
||||||
|
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
Task task = new Task();
|
||||||
|
task.execute();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Task extends SwingWorker<Integer, Integer> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Integer doInBackground() throws Exception {
|
||||||
|
int i = 0;
|
||||||
|
while (i < 100) {
|
||||||
|
Thread.sleep(100);
|
||||||
|
i++;
|
||||||
|
|
||||||
|
progressBar.setValue(i);
|
||||||
|
publish(i);
|
||||||
|
}
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void done() {
|
||||||
|
progressBar.setValue(100);
|
||||||
|
progressBar.setString("Done!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new ProgressBarExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.progress;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class ProgressMonitorExample extends JPanel {
|
||||||
|
|
||||||
|
public ProgressMonitorExample() {
|
||||||
|
super();
|
||||||
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
|
||||||
|
|
||||||
|
final JButton button = new JButton("Start");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
this.add(button);
|
||||||
|
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
Task task = new Task();
|
||||||
|
task.execute();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Task extends SwingWorker<Integer, Integer> {
|
||||||
|
private final ProgressMonitor progressMonitor;
|
||||||
|
Task(){
|
||||||
|
super();
|
||||||
|
progressMonitor = new ProgressMonitor(ProgressMonitorExample.this,
|
||||||
|
"Progress Monitor", "Running a long task..", 0, 100);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected Integer doInBackground() throws Exception {
|
||||||
|
int i = 0;
|
||||||
|
while (i < 100) {
|
||||||
|
if(progressMonitor.isCanceled()){
|
||||||
|
this.cancel(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread.sleep(100);
|
||||||
|
i++;
|
||||||
|
|
||||||
|
progressMonitor.setProgress(i);
|
||||||
|
publish(i);
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void done() {
|
||||||
|
if (!progressMonitor.isCanceled()) {
|
||||||
|
System.out.println("Job done.");
|
||||||
|
progressMonitor.setProgress(100);
|
||||||
|
progressMonitor.setNote("Done!");
|
||||||
|
} else {
|
||||||
|
System.out.println("User canceled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
progressMonitor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new ProgressMonitorExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.slider;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Dictionary;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
public class SliderExample extends JPanel {
|
||||||
|
public SliderExample() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
final JLabel label = new JLabel();
|
||||||
|
|
||||||
|
final JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 50);
|
||||||
|
slider.setMajorTickSpacing(10);
|
||||||
|
slider.setMinorTickSpacing(5);
|
||||||
|
slider.setPaintTicks(true);
|
||||||
|
slider.setPaintLabels(true);
|
||||||
|
slider.setPaintTrack(true);
|
||||||
|
|
||||||
|
// 개발자 정의 라벨
|
||||||
|
Dictionary<Integer,JLabel> dict = new Hashtable<>();
|
||||||
|
dict.put(0, new JLabel("Minimum"));
|
||||||
|
dict.put(50, new JLabel("50"));
|
||||||
|
dict.put(100, new JLabel("Maximum"));
|
||||||
|
slider.setLabelTable(dict);
|
||||||
|
|
||||||
|
label.setText(String.valueOf(slider.getValue()));
|
||||||
|
|
||||||
|
|
||||||
|
slider.addChangeListener(new ChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void stateChanged(ChangeEvent changeEvent) {
|
||||||
|
JSlider eventSource = (JSlider) changeEvent.getSource();
|
||||||
|
if (!eventSource.getValueIsAdjusting()){
|
||||||
|
label.setText(String.valueOf(eventSource.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.add(label);
|
||||||
|
this.add(slider);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new SliderExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.spinner;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Dictionary;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
public class SpinnerExample extends JPanel {
|
||||||
|
|
||||||
|
public SpinnerExample() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
final String[] data = {"Do", "Re", "Mi", "Fa", "Sol", "La", "Si"};
|
||||||
|
final JSpinner spinner = new JSpinner(new SpinnerListModel(data));
|
||||||
|
|
||||||
|
spinner.addChangeListener(new ChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void stateChanged(ChangeEvent changeEvent) {
|
||||||
|
JSpinner eventSource = (JSpinner) changeEvent.getSource();
|
||||||
|
// 모델을 통해서 선택된 값을 가져온다.
|
||||||
|
System.out.println(eventSource.getModel().getValue());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.add(spinner);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new SpinnerExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.table;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.TableModelEvent;
|
||||||
|
import javax.swing.event.TableModelListener;
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
import javax.swing.table.TableCellRenderer;
|
||||||
|
import javax.swing.table.TableModel;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class Table2Example extends JPanel {
|
||||||
|
|
||||||
|
public Table2Example() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
|
||||||
|
final JTable table = new JTable(new MyTableModel());
|
||||||
|
table.setFillsViewportHeight(true);
|
||||||
|
table.setRowSelectionAllowed(true);
|
||||||
|
table.getColumnModel().getColumn(0).setPreferredWidth(80);
|
||||||
|
table.getColumnModel().getColumn(1).setPreferredWidth(40);
|
||||||
|
table.getColumnModel().getColumn(2).setPreferredWidth(180);
|
||||||
|
|
||||||
|
table.getModel().addTableModelListener(new TableModelListener() {
|
||||||
|
@Override
|
||||||
|
public void tableChanged(TableModelEvent tableModelEvent) {
|
||||||
|
int row = tableModelEvent.getFirstRow();
|
||||||
|
int column = tableModelEvent.getColumn();
|
||||||
|
TableModel model = (TableModel)tableModelEvent.getSource();
|
||||||
|
System.out.println(model.getValueAt(row,column));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
table.setDefaultRenderer(String.class, new MyTableRenderer());
|
||||||
|
|
||||||
|
add(new JScrollPane(table), BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
private static class Person {
|
||||||
|
private String name;
|
||||||
|
private int age;
|
||||||
|
private String address;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MyTableModel extends AbstractTableModel {
|
||||||
|
final java.util.List<String> header = Arrays.asList("이름", "나이", "주소");
|
||||||
|
final java.util.List<Person> data = new ArrayList<>();
|
||||||
|
|
||||||
|
MyTableModel() {
|
||||||
|
super();
|
||||||
|
data.add(new Person("Charlie", 13, "서울"));
|
||||||
|
data.add(new Person("Steve", 34, "서울"));
|
||||||
|
data.add(new Person("Jane", 23, "서울"));
|
||||||
|
data.add(new Person("Jack", 48, "서울"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRowCount() {
|
||||||
|
return data.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return header.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValueAt(int row, int column) {
|
||||||
|
Person person = data.get(row);
|
||||||
|
switch (column) {
|
||||||
|
case 0:
|
||||||
|
return person.name;
|
||||||
|
case 1:
|
||||||
|
return person.age;
|
||||||
|
case 2:
|
||||||
|
return person.address;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColumnName(int column) {
|
||||||
|
return header.get(column);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> getColumnClass(int column) {
|
||||||
|
switch (column) {
|
||||||
|
case 0:
|
||||||
|
return String.class;
|
||||||
|
case 1:
|
||||||
|
return Integer.class;
|
||||||
|
case 2:
|
||||||
|
return String.class;
|
||||||
|
}
|
||||||
|
return Object.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||||
|
return columnIndex == 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
||||||
|
Person person = data.get(rowIndex);
|
||||||
|
switch (columnIndex) {
|
||||||
|
case 0:
|
||||||
|
person.name = (String) aValue;
|
||||||
|
return;
|
||||||
|
case 1:
|
||||||
|
person.age = (Integer) aValue;
|
||||||
|
return;
|
||||||
|
case 2:
|
||||||
|
person.address = (String) aValue;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fireTableCellUpdated(rowIndex,columnIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MyTableRenderer extends JPanel implements TableCellRenderer {
|
||||||
|
private JLabel jLabel;
|
||||||
|
MyTableRenderer(){
|
||||||
|
super();
|
||||||
|
jLabel = new JLabel();
|
||||||
|
add(jLabel, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Component getTableCellRendererComponent(JTable jTable, Object value,
|
||||||
|
boolean isSelected, boolean haFocus, int row, int column) {
|
||||||
|
//do something
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new Table2Example());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.table;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class TableExample extends JPanel {
|
||||||
|
|
||||||
|
public TableExample() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
final Object[] header = {"이름", "나이", "주소"};
|
||||||
|
final Object[][] data = {
|
||||||
|
new Object[]{"Charlie", 13, "서울"},
|
||||||
|
new Object[]{"Steve", 34, "대전"},
|
||||||
|
new Object[]{"Jane", 23, "대구"},
|
||||||
|
new Object[]{"Jack", 48, "부산"},
|
||||||
|
};
|
||||||
|
|
||||||
|
final JTable table = new JTable(data, header);
|
||||||
|
table.setFillsViewportHeight(true);
|
||||||
|
table.setRowSelectionAllowed(true);
|
||||||
|
table.getColumnModel().getColumn(0).setPreferredWidth(80);
|
||||||
|
table.getColumnModel().getColumn(1).setPreferredWidth(40);
|
||||||
|
table.getColumnModel().getColumn(2).setPreferredWidth(180);
|
||||||
|
|
||||||
|
|
||||||
|
add(new JScrollPane(table), BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new TableExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.textfield;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.text.MaskFormatter;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
|
|
||||||
|
public class FormattedTextFieldExample extends JPanel {
|
||||||
|
public FormattedTextFieldExample() throws ParseException {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
final NumberFormat numberFormat = NumberFormat.getPercentInstance();
|
||||||
|
numberFormat.setMaximumFractionDigits(2);
|
||||||
|
numberFormat.setMinimumFractionDigits(2);
|
||||||
|
|
||||||
|
final JFormattedTextField textField = new JFormattedTextField(numberFormat);
|
||||||
|
textField.setValue(0.35);
|
||||||
|
textField.setColumns(10);
|
||||||
|
textField.setEditable(true);
|
||||||
|
|
||||||
|
textField.addPropertyChangeListener("value", new PropertyChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
|
||||||
|
System.out.println(textField.getValue() + " vs. " + textField.getText());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 레이아웃에 추가
|
||||||
|
add(textField);
|
||||||
|
|
||||||
|
final MaskFormatter maskFormatter = new MaskFormatter("###-####-####");
|
||||||
|
final JFormattedTextField textField2 = new JFormattedTextField(maskFormatter);
|
||||||
|
|
||||||
|
add(textField2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) throws ParseException {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new FormattedTextFieldExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.textfield;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class TextAreaExample extends JPanel {
|
||||||
|
public TextAreaExample() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
final JTextField textField = new JTextField();
|
||||||
|
|
||||||
|
final JTextArea textArea = new JTextArea();
|
||||||
|
textArea.setText("Hello\n");
|
||||||
|
textArea.setEditable(true);
|
||||||
|
textArea.setLineWrap(true);
|
||||||
|
textArea.setWrapStyleWord(true);
|
||||||
|
|
||||||
|
add(textField, BorderLayout.NORTH);
|
||||||
|
add(new JScrollPane(textArea), BorderLayout.CENTER);
|
||||||
|
|
||||||
|
textField.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
textArea.append(textField.getText() + "\n");
|
||||||
|
textArea.setCaretPosition(textArea.getDocument().getLength());
|
||||||
|
textField.setText(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new TextAreaExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.textfield;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
public class TextFieldExample extends JPanel {
|
||||||
|
public TextFieldExample() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
final JTextField textField = new JTextField();
|
||||||
|
textField.setText("Hello");
|
||||||
|
final JButton button = new JButton("Click");
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
System.out.println(textField.getText());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 레이아웃에 추가
|
||||||
|
add(textField);
|
||||||
|
add(button);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new TextFieldExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.toolbar;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class ToolBarExample extends JPanel {
|
||||||
|
public ToolBarExample() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
final JToolBar toolBar = new JToolBar("I'm a ToolBar");
|
||||||
|
|
||||||
|
toolBar.add(new JButton("Button 1"));
|
||||||
|
toolBar.add(new JButton("Button 2"));
|
||||||
|
toolBar.addSeparator();
|
||||||
|
toolBar.add(new JTextField("Hello"));
|
||||||
|
|
||||||
|
toolBar.setRollover(true);
|
||||||
|
toolBar.setFloatable(true);
|
||||||
|
|
||||||
|
add(toolBar, BorderLayout.NORTH);
|
||||||
|
add(new JPanel(), BorderLayout.CENTER);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new ToolBarExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.components.tree;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.*;
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
import javax.swing.tree.ExpandVetoException;
|
||||||
|
import javax.swing.tree.TreeSelectionModel;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class TreeExample extends JPanel {
|
||||||
|
public TreeExample() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
final MyTreeNode rootNode = new MyTreeNode();
|
||||||
|
final JTree tree = new JTree(rootNode);
|
||||||
|
tree.setRootVisible(true);
|
||||||
|
tree.putClientProperty("JTree.lineStyle", "Horizontal"); // Angled | Horizontal | None
|
||||||
|
|
||||||
|
add(new JScrollPane(tree), BorderLayout.CENTER);
|
||||||
|
|
||||||
|
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||||
|
tree.addTreeSelectionListener(new TreeSelectionListener() {
|
||||||
|
@Override
|
||||||
|
public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
|
||||||
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
|
||||||
|
if(null==node) return;
|
||||||
|
|
||||||
|
Object nodeInfo = node.getUserObject();
|
||||||
|
if (node.isLeaf()){
|
||||||
|
System.out.println("It's a page. " + nodeInfo);
|
||||||
|
} else {
|
||||||
|
System.out.println("It's a folder. " + nodeInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tree.getModel().addTreeModelListener(new TreeModelListener() {
|
||||||
|
@Override
|
||||||
|
public void treeNodesChanged(TreeModelEvent treeModelEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void treeNodesInserted(TreeModelEvent treeModelEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void treeNodesRemoved(TreeModelEvent treeModelEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void treeStructureChanged(TreeModelEvent treeModelEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tree.addTreeExpansionListener(new TreeExpansionListener() {
|
||||||
|
@Override
|
||||||
|
public void treeExpanded(TreeExpansionEvent treeExpansionEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void treeCollapsed(TreeExpansionEvent treeExpansionEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
|
||||||
|
@Override
|
||||||
|
public void treeWillExpand(TreeExpansionEvent treeExpansionEvent) throws ExpandVetoException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void treeWillCollapse(TreeExpansionEvent treeExpansionEvent) throws ExpandVetoException {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MyTreeNode extends DefaultMutableTreeNode {
|
||||||
|
MyTreeNode(){
|
||||||
|
super("The Book");
|
||||||
|
|
||||||
|
final DefaultMutableTreeNode chapter1 = new DefaultMutableTreeNode("Chapter 1");
|
||||||
|
chapter1.add(new DefaultMutableTreeNode("Page 1"));
|
||||||
|
chapter1.add(new DefaultMutableTreeNode("Page 2"));
|
||||||
|
final DefaultMutableTreeNode chapter2 = new DefaultMutableTreeNode("Chapter 2");
|
||||||
|
chapter2.add(new DefaultMutableTreeNode("Page 3"));
|
||||||
|
chapter2.add(new DefaultMutableTreeNode("Page 4"));
|
||||||
|
chapter2.add(new DefaultMutableTreeNode("Page 5"));
|
||||||
|
|
||||||
|
add(chapter1);
|
||||||
|
add(chapter2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new TreeExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.container;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Dictionary;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
public class SplitpaneExample extends JSplitPane {
|
||||||
|
public SplitpaneExample() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
final JPanel leftPanel = new JPanel(new BorderLayout());
|
||||||
|
leftPanel.add(new JLabel("A"), BorderLayout.CENTER);
|
||||||
|
final JPanel rightPanel = new JPanel(new BorderLayout());
|
||||||
|
rightPanel.add(new JLabel("B"), BorderLayout.CENTER);
|
||||||
|
|
||||||
|
setOrientation(JSplitPane.HORIZONTAL_SPLIT);
|
||||||
|
setDividerLocation(280);
|
||||||
|
leftPanel.setMinimumSize(new Dimension(200,0));
|
||||||
|
setLeftComponent(leftPanel);
|
||||||
|
setRightComponent(rightPanel);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new SplitpaneExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.container;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class TabbedpaneExample extends JTabbedPane {
|
||||||
|
public TabbedpaneExample() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
final JPanel panel1 = new JPanel(new BorderLayout());
|
||||||
|
panel1.add(new JLabel("A"), BorderLayout.CENTER);
|
||||||
|
final JPanel panel2 = new JPanel(new BorderLayout());
|
||||||
|
panel2.add(new JLabel("B"), BorderLayout.CENTER);
|
||||||
|
|
||||||
|
addTab("Tab 1", panel1);
|
||||||
|
addTab("Tab 2", panel2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new TabbedpaneExample());
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.dialog;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
|
||||||
|
public class DialogExample extends JPanel {
|
||||||
|
private JFrame jFrame;
|
||||||
|
|
||||||
|
public DialogExample(JFrame jFrame) {
|
||||||
|
super(new FlowLayout());
|
||||||
|
this.jFrame = jFrame;
|
||||||
|
|
||||||
|
final JButton button1 = new JButton("Message Dialog");
|
||||||
|
final JButton button2 = new JButton("Option Dialog");
|
||||||
|
final JButton button3 = new JButton("Option Dialog 2");
|
||||||
|
|
||||||
|
// 레이아웃에 추가
|
||||||
|
add(button1);
|
||||||
|
add(button2);
|
||||||
|
add(button3);
|
||||||
|
|
||||||
|
// 액션 리스너를 통해서 클릭 이벤트를 받는다.
|
||||||
|
final ActionListener actionListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
JButton button = (JButton) actionEvent.getSource();
|
||||||
|
if (button == button1) {
|
||||||
|
JOptionPane
|
||||||
|
.showMessageDialog(DialogExample.this, "Hello");
|
||||||
|
} else if (button == button2) {
|
||||||
|
final String[] options = {"A", "B", "C", "D"};
|
||||||
|
int response = JOptionPane.showOptionDialog(DialogExample.this, "Make a decision!", "Pick one",
|
||||||
|
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
|
||||||
|
options, options[0]);
|
||||||
|
System.out.println(options[response]);
|
||||||
|
} else if (button == button3) {
|
||||||
|
final JOptionPane optionPane = new JOptionPane("Hello~",
|
||||||
|
JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
|
||||||
|
final JDialog jDialog = new JDialog(jFrame, "Hello", true);
|
||||||
|
jDialog.setContentPane(optionPane);
|
||||||
|
jDialog.pack();
|
||||||
|
jDialog.setVisible(true);
|
||||||
|
//jDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
|
||||||
|
optionPane.addPropertyChangeListener(new PropertyChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
System.out.println(optionPane.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
button1.addActionListener(actionListener);
|
||||||
|
button2.addActionListener(actionListener);
|
||||||
|
button3.addActionListener(actionListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new DialogExample(jFrame));
|
||||||
|
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.dragdrop;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.text.JTextComponent;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.datatransfer.DataFlavor;
|
||||||
|
import java.awt.datatransfer.StringSelection;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class DragDropExample extends JPanel {
|
||||||
|
DragDropExample() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
final JList<String> list = new JList<>(new String[]{"A", "B", "C"});
|
||||||
|
list.setLayoutOrientation(JList.VERTICAL);
|
||||||
|
list.setDragEnabled(true);
|
||||||
|
list.setTransferHandler(new TransferHandler() {
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {
|
||||||
|
return TransferHandler.COPY;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Transferable createTransferable(JComponent c) {
|
||||||
|
return new StringSelection(((JList<String>) c).getSelectedValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void exportDone(JComponent source, Transferable data, int action) {
|
||||||
|
if (action == TransferHandler.COPY) {
|
||||||
|
System.out.println("Copy done.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final JTextArea textArea = new JTextArea( " ");
|
||||||
|
textArea.setDropMode(DropMode.INSERT);
|
||||||
|
textArea.setTransferHandler(new TransferHandler() {
|
||||||
|
@Override
|
||||||
|
public boolean importData(TransferSupport support) {
|
||||||
|
if (!canImport(support)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Transferable transferable = support.getTransferable();
|
||||||
|
String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
|
||||||
|
|
||||||
|
JTextComponent.DropLocation dropLocation = (JTextComponent.DropLocation) support.getDropLocation();
|
||||||
|
int idx = dropLocation.getIndex();
|
||||||
|
|
||||||
|
textArea.insert(data, idx);
|
||||||
|
return true;
|
||||||
|
} catch (UnsupportedFlavorException | IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canImport(TransferSupport support) {
|
||||||
|
if (support.isDataFlavorSupported(DataFlavor.stringFlavor) &&
|
||||||
|
(support.getSourceDropActions() & COPY)==COPY) {
|
||||||
|
support.setDropAction(COPY);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
list.setMinimumSize(new Dimension(300, 0));
|
||||||
|
add(list, BorderLayout.LINE_START);
|
||||||
|
add(textArea, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new DragDropExample());
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.frame;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.awt.geom.Ellipse2D;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class CustomFrameExample {
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
if (Desktop.isDesktopSupported()) {
|
||||||
|
final Desktop desktop = Desktop.getDesktop();
|
||||||
|
if(desktop.isSupported(Desktop.Action.BROWSE_FILE_DIR)){
|
||||||
|
desktop.browseFileDirectory(new File(System.getProperty("user.home")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 컨텐트 패널에 버튼 등의 컴포넌트를 구성한다.
|
||||||
|
final JPanel contentPane = new JPanel();
|
||||||
|
//contentPane.setBackground(Color.PINK);
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(contentPane);
|
||||||
|
jFrame.setUndecorated(true);
|
||||||
|
|
||||||
|
final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||||
|
final GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
|
||||||
|
|
||||||
|
if (graphicsDevice.isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.TRANSLUCENT)){
|
||||||
|
jFrame.setOpacity(0.7f);
|
||||||
|
System.out.println("set opacity");
|
||||||
|
}
|
||||||
|
jFrame.addComponentListener(new ComponentAdapter() {
|
||||||
|
@Override
|
||||||
|
public void componentResized(ComponentEvent e) {
|
||||||
|
jFrame.setShape(new Ellipse2D.Double(0,0, jFrame.getWidth(), jFrame.getHeight()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(graphicsDevice.isFullScreenSupported()){
|
||||||
|
graphicsDevice.setFullScreenWindow(jFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.frame;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class FrameExample {
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
// 컨텐트 패널에 버튼 등의 컴포넌트를 구성한다.
|
||||||
|
final JPanel contentPane = new JPanel();
|
||||||
|
contentPane.setBackground(Color.PINK);
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(contentPane);
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 어플리케이션 종료시에 처리할 내용은 셧다운 훅을 사용한다.
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
// do something
|
||||||
|
}));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.frame;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class InternalFrameExample {
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
// 컨텐트 패널에 버튼 등의 컴포넌트를 구성한다.
|
||||||
|
final JInternalFrame internalFrame = new JInternalFrame("Frame 1");
|
||||||
|
internalFrame.setSize(400,300);
|
||||||
|
internalFrame.setBackground(Color.PINK);
|
||||||
|
internalFrame.setVisible(true);
|
||||||
|
internalFrame.setIconifiable(true);
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
JDesktopPane jDesktopPane = new JDesktopPane();
|
||||||
|
jDesktopPane.add(internalFrame);
|
||||||
|
jFrame.setContentPane(jDesktopPane);
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 어플리케이션 종료시에 처리할 내용은 셧다운 훅을 사용한다.
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
// do something
|
||||||
|
}));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.frame;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class LookAndFeelExample {
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
try {
|
||||||
|
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
||||||
|
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
|
||||||
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
|
||||||
|
UnsupportedLookAndFeelException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
Arrays.stream(UIManager.getInstalledLookAndFeels()).forEach(lookAndFeelInfo -> System.out.println(lookAndFeelInfo));
|
||||||
|
// 컨텐트 패널에 버튼 등의 컴포넌트를 구성한다.
|
||||||
|
final JPanel contentPane = new JPanel();
|
||||||
|
contentPane.setBackground(Color.PINK);
|
||||||
|
contentPane.add(new JButton("Hello"));
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(contentPane);
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.frame;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class SplashScreenExample {
|
||||||
|
public void systemTray(){
|
||||||
|
if(SystemTray.isSupported()){
|
||||||
|
SystemTray systemTray = SystemTray.getSystemTray();
|
||||||
|
//systemTray.add(new TrayIcon(...));
|
||||||
|
TrayIcon trayIcon = new TrayIcon(null,"", new PopupMenu());
|
||||||
|
//trayIcon.set
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
final SplashScreen splashScreen = SplashScreen.getSplashScreen();
|
||||||
|
Graphics2D graphics2D = splashScreen.createGraphics();
|
||||||
|
splashScreen.close();
|
||||||
|
|
||||||
|
// 컨텐트 패널에 버튼 등의 컴포넌트를 구성한다.
|
||||||
|
final JPanel contentPane = new JPanel();
|
||||||
|
contentPane.setBackground(Color.PINK);
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(contentPane);
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.graphics;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.font.TextAttribute;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.GeneralPath;
|
||||||
|
import java.awt.geom.Path2D;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class GraphicsExample extends JPanel {
|
||||||
|
|
||||||
|
GraphicsExample() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
final Graphics2D graphics2D = (Graphics2D) g;
|
||||||
|
Stroke stroke = new BasicStroke(1f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.f);
|
||||||
|
Paint paint = new GradientPaint(0,0,Color.BLUE,100,0,Color.GREEN);
|
||||||
|
|
||||||
|
graphics2D.setStroke(stroke);
|
||||||
|
graphics2D.setPaint(paint);
|
||||||
|
|
||||||
|
Path2D path = new GeneralPath(GeneralPath.WIND_NON_ZERO);
|
||||||
|
path.moveTo(20,20);
|
||||||
|
path.lineTo(100,20);
|
||||||
|
path.lineTo(100,100);
|
||||||
|
|
||||||
|
graphics2D.draw(path);
|
||||||
|
|
||||||
|
|
||||||
|
graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
|
Font font = graphics2D.getFont().deriveFont(14.f);
|
||||||
|
graphics2D.setFont(font);
|
||||||
|
FontMetrics fontMetrics = graphics2D.getFontMetrics(font);
|
||||||
|
int textHeight = fontMetrics.getHeight();
|
||||||
|
int textWidth = fontMetrics.stringWidth("Hello");
|
||||||
|
graphics2D.drawString("Hello", 100, 100);
|
||||||
|
graphics2D.drawRect(100,100-textHeight,textWidth,textHeight);
|
||||||
|
|
||||||
|
|
||||||
|
HashMap<TextAttribute,Object> map = new HashMap<>();
|
||||||
|
map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
|
||||||
|
font = font.deriveFont(map);
|
||||||
|
|
||||||
|
AffineTransform transformX = graphics2D.getTransform();
|
||||||
|
AffineTransform transform = new AffineTransform();
|
||||||
|
transform.rotate(45);
|
||||||
|
graphics2D.transform(transform);
|
||||||
|
graphics2D.draw(new Rectangle2D.Float(0,0,100,100));
|
||||||
|
graphics2D.setTransform(transformX);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
// 컨텐트 패널에 버튼 등의 컴포넌트를 구성한다.
|
||||||
|
final JPanel contentPane = new JPanel();
|
||||||
|
contentPane.setBackground(Color.PINK);
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new GraphicsExample());
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.layouts;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class BorderLayoutExample extends JPanel {
|
||||||
|
|
||||||
|
BorderLayoutExample() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
final JButton button1 = new JButton("Button 1");
|
||||||
|
final JButton button2 = new JButton("Button 2");
|
||||||
|
final JButton button3 = new JButton("Button 3");
|
||||||
|
final JButton button4 = new JButton("Button 4");
|
||||||
|
final JButton button5 = new JButton("Button 5");
|
||||||
|
|
||||||
|
add(button1, BorderLayout.NORTH);
|
||||||
|
add(button2, BorderLayout.WEST);
|
||||||
|
add(button3, BorderLayout.CENTER);
|
||||||
|
add(button4, BorderLayout.EAST);
|
||||||
|
add(button5, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new BorderLayoutExample());
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.layouts;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class BoxLayoutExample extends JPanel {
|
||||||
|
|
||||||
|
BoxLayoutExample() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
final BoxLayout boxLayout = new BoxLayout(this, BoxLayout.LINE_AXIS);
|
||||||
|
setLayout(boxLayout);
|
||||||
|
|
||||||
|
final JButton button1 = new JButton("Button 1");
|
||||||
|
final JButton button2 = new JButton("Button 2");
|
||||||
|
final JButton button3 = new JButton("Button 3");
|
||||||
|
final JButton button4 = new JButton("Button 4");
|
||||||
|
final JButton button5 = new JButton("Button 5");
|
||||||
|
|
||||||
|
add(button1);
|
||||||
|
add(button2);
|
||||||
|
add(button3);
|
||||||
|
add(button4);
|
||||||
|
add(button5);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new BoxLayoutExample());
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.layouts;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class CardLayoutExample extends JPanel {
|
||||||
|
|
||||||
|
CardLayoutExample() {
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
final JButton button1 = new JButton("Button 1");
|
||||||
|
final JButton button2 = new JButton("Button 2");
|
||||||
|
final JButton button3 = new JButton("Button 3");
|
||||||
|
final JButton button4 = new JButton("Button 4");
|
||||||
|
final JButton button5 = new JButton("Button 5");
|
||||||
|
final JToolBar toolBar =new JToolBar();
|
||||||
|
toolBar.add(button1);
|
||||||
|
toolBar.add(button2);
|
||||||
|
toolBar.add(button3);
|
||||||
|
toolBar.add(button4);
|
||||||
|
toolBar.add(button5);
|
||||||
|
add(toolBar, BorderLayout.PAGE_START);
|
||||||
|
|
||||||
|
|
||||||
|
final JPanel cardPanel = new JPanel(new CardLayout());
|
||||||
|
cardPanel.add(new JLabel("A"), "card 1");
|
||||||
|
cardPanel.add(new JLabel("B"), "card 2");
|
||||||
|
add(cardPanel, BorderLayout.PAGE_END);
|
||||||
|
|
||||||
|
button1.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
CardLayout layout = (CardLayout) cardPanel.getLayout();
|
||||||
|
layout.show(cardPanel, "card 1");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
button2.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
CardLayout layout = (CardLayout) cardPanel.getLayout();
|
||||||
|
layout.show(cardPanel, "card 2");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new CardLayoutExample());
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.layouts;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class FlowLayoutExample extends JPanel {
|
||||||
|
|
||||||
|
FlowLayoutExample() {
|
||||||
|
super(new FlowLayout());
|
||||||
|
|
||||||
|
final JButton button1 = new JButton("Button 1");
|
||||||
|
final JButton button2 = new JButton("Button 2");
|
||||||
|
final JButton button3 = new JButton("Button 3");
|
||||||
|
final JButton button4 = new JButton("Button 4");
|
||||||
|
final JButton button5 = new JButton("Button 5");
|
||||||
|
|
||||||
|
add(button1);
|
||||||
|
add(button2);
|
||||||
|
add(button3);
|
||||||
|
add(button4);
|
||||||
|
add(button5);
|
||||||
|
|
||||||
|
FlowLayout layout = (FlowLayout) this.getLayout();
|
||||||
|
layout.setAlignment(FlowLayout.TRAILING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new FlowLayoutExample());
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.layouts;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class GridBagLayoutExample extends JPanel {
|
||||||
|
|
||||||
|
GridBagLayoutExample() {
|
||||||
|
super(new GridBagLayout());
|
||||||
|
|
||||||
|
final JButton button1 = new JButton("Button 1");
|
||||||
|
final JButton button2 = new JButton("Button 2");
|
||||||
|
final JButton button3 = new JButton("Button 3");
|
||||||
|
final JButton button4 = new JButton("Button 4");
|
||||||
|
final JButton button5 = new JButton("Button 5");
|
||||||
|
|
||||||
|
GridBagConstraints constraints = new GridBagConstraints();
|
||||||
|
add(button1, constraints);
|
||||||
|
constraints.gridx=1;
|
||||||
|
add(button2, constraints);
|
||||||
|
constraints.gridx=0;
|
||||||
|
constraints.gridy=1;
|
||||||
|
add(button3, constraints);
|
||||||
|
constraints.gridx=1;
|
||||||
|
add(button4, constraints);
|
||||||
|
constraints.gridx=0;
|
||||||
|
constraints.gridy=2;
|
||||||
|
constraints.gridwidth=2;
|
||||||
|
constraints.fill=GridBagConstraints.HORIZONTAL;
|
||||||
|
add(button5, constraints);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new GridBagLayoutExample());
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.layouts;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class GridLayoutExample extends JPanel {
|
||||||
|
|
||||||
|
GridLayoutExample() {
|
||||||
|
super(new GridLayout(3,2));
|
||||||
|
|
||||||
|
final JButton button1 = new JButton("Button 1");
|
||||||
|
final JButton button2 = new JButton("Button 2");
|
||||||
|
final JButton button3 = new JButton("Button 3");
|
||||||
|
final JButton button4 = new JButton("Button 4");
|
||||||
|
final JButton button5 = new JButton("Button 5");
|
||||||
|
|
||||||
|
add(button1);
|
||||||
|
add(button2);
|
||||||
|
add(button3);
|
||||||
|
add(button4);
|
||||||
|
add(button5);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new GridLayoutExample());
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.layouts;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class GroupLayoutExample extends JPanel {
|
||||||
|
|
||||||
|
GroupLayoutExample() {
|
||||||
|
super();
|
||||||
|
final GroupLayout layout = new GroupLayout(this);
|
||||||
|
layout.setAutoCreateGaps(true);
|
||||||
|
layout.setAutoCreateContainerGaps(true);
|
||||||
|
setLayout(layout);
|
||||||
|
|
||||||
|
final JButton button1 = new JButton("Button 1");
|
||||||
|
final JButton button2 = new JButton("Button 2");
|
||||||
|
final JButton button3 = new JButton("Button 3");
|
||||||
|
final JButton button4 = new JButton("Button 4");
|
||||||
|
final JButton button5 = new JButton("Button 5");
|
||||||
|
|
||||||
|
layout.setHorizontalGroup(layout.createSequentialGroup()
|
||||||
|
.addComponent(button1)
|
||||||
|
.addComponent(button2)
|
||||||
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||||
|
.addComponent(button3)
|
||||||
|
.addComponent(button4)
|
||||||
|
.addComponent(button5))
|
||||||
|
);
|
||||||
|
layout.setVerticalGroup(layout.createSequentialGroup()
|
||||||
|
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
|
||||||
|
.addComponent(button1)
|
||||||
|
.addComponent(button2)
|
||||||
|
.addComponent(button3))
|
||||||
|
.addComponent(button4)
|
||||||
|
.addComponent(button5));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new GroupLayoutExample());
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.layouts;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class SpringLayoutExample extends JPanel {
|
||||||
|
|
||||||
|
SpringLayoutExample() {
|
||||||
|
super(new SpringLayout());
|
||||||
|
|
||||||
|
|
||||||
|
final JButton button1 = new JButton("Button 1");
|
||||||
|
final JButton button2 = new JButton("Button 2");
|
||||||
|
final JButton button3 = new JButton("Button 3");
|
||||||
|
final JButton button4 = new JButton("Button 4");
|
||||||
|
final JButton button5 = new JButton("Button 5");
|
||||||
|
|
||||||
|
add(button1);
|
||||||
|
add(button2);
|
||||||
|
add(button3);
|
||||||
|
add(button4);
|
||||||
|
add(button5);
|
||||||
|
|
||||||
|
final SpringLayout layout = (SpringLayout) getLayout();
|
||||||
|
layout.putConstraint(SpringLayout.BASELINE, button2, 0,
|
||||||
|
SpringLayout.BASELINE, button1); // 버튼 2의 베이스라인은 버튼 1의 베이스라인과 같다.
|
||||||
|
layout.putConstraint(SpringLayout.BASELINE, button3, 0,
|
||||||
|
SpringLayout.BASELINE, button2); // 버튼 3의 베이스라인은 버튼 2의 베이스라인과 같다.
|
||||||
|
layout.putConstraint(SpringLayout.WEST, button2, 10,
|
||||||
|
SpringLayout.EAST, button1); // 버튼 2의 왼쪽은 버튼 1의 오른쪽과 10만큼 떨어져 있다.
|
||||||
|
layout.putConstraint(SpringLayout.WEST, button3, 10,
|
||||||
|
SpringLayout.EAST, button2);
|
||||||
|
layout.putConstraint(SpringLayout.NORTH, button4, 10,
|
||||||
|
SpringLayout.SOUTH, button3);
|
||||||
|
layout.putConstraint(SpringLayout.NORTH, button5, 10,
|
||||||
|
SpringLayout.SOUTH, button4);
|
||||||
|
layout.putConstraint(SpringLayout.EAST, button4, 0,
|
||||||
|
SpringLayout.EAST, button3);
|
||||||
|
layout.putConstraint(SpringLayout.EAST, button5, 0,
|
||||||
|
SpringLayout.EAST, button4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(new SpringLayoutExample());
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package com.elex_project.examples;
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.thread;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.text.JTextComponent;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
public class PrintingTaskExample {
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
private static class PrintingTask extends SwingWorker<Object, Object>{
|
||||||
|
private JTextComponent textComponent;
|
||||||
|
private MessageFormat header, footer;
|
||||||
|
private boolean interactive;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object doInBackground() throws Exception {
|
||||||
|
boolean completed = textComponent.print(header,footer,true,null,null,interactive);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
// 컨텐트 패널에 버튼 등의 컴포넌트를 구성한다.
|
||||||
|
final JPanel contentPane = new JPanel();
|
||||||
|
contentPane.setBackground(Color.PINK);
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(contentPane);
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 어플리케이션 종료시에 처리할 내용은 셧다운 훅을 사용한다.
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
// do something
|
||||||
|
}));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.elex_project.examples.thread;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
public class ThreadExample {
|
||||||
|
|
||||||
|
public void something(){
|
||||||
|
final SwingWorker<Image[], Integer> swingWorker = new SwingWorker<Image[], Integer>() {
|
||||||
|
@Override
|
||||||
|
protected Image[] doInBackground() throws Exception {
|
||||||
|
Image[] images = new Image[]{};
|
||||||
|
// do something
|
||||||
|
int i=0;
|
||||||
|
while (i<100){
|
||||||
|
publish(i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return images;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void process(List<Integer> chunks) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void done() {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
swingWorker.execute();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Image[] imgs = swingWorker.get(); // 작업이 끝날 때까지 대기 상태가 된다.
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void something2(){
|
||||||
|
final Timer timer = new Timer(0, new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
timer.start();
|
||||||
|
}
|
||||||
|
public static void main(String... args) {
|
||||||
|
// 컨텐트 패널에 버튼 등의 컴포넌트를 구성한다.
|
||||||
|
final JPanel contentPane = new JPanel();
|
||||||
|
contentPane.setBackground(Color.PINK);
|
||||||
|
|
||||||
|
// 프레임을 생성한다.
|
||||||
|
final JFrame jFrame = new JFrame();
|
||||||
|
jFrame.setTitle("Example");
|
||||||
|
jFrame.setSize(800, 600);
|
||||||
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
jFrame.setContentPane(contentPane);
|
||||||
|
|
||||||
|
// 이벤트 디스패치 스레드에서 프레임을 표시한다.
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
jFrame.setVisible(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 어플리케이션 종료시에 처리할 내용은 셧다운 훅을 사용한다.
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
// do something
|
||||||
|
}));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
package com.elex_project.sample;
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.elex_project.sample;
|
package com.elex_project.examples;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
Reference in New Issue
Block a user