TabFolder를 이용하여 탭화면 구성하기
- 프로그래밍/SWT & JFace
- 2016. 2. 10. 19:39
SWT/JFace 어플리케이션 플로그래밍시에 TabFolder를 이용하여 화면을 구성하는 방법을 알아보자.
TabFolder 인스턴스 생성
각 TabPage를 담는 컨테이너 역할을 한다.
1 |
TabFolder tf = new TabFolder(container, SWT.NONE); |
cs |
TabItem 인스턴스 생성
TabItem인스턴스를 생성하고 생성자의 첫번째 인자로 TabFolder의 인스턴스를 넘겨준다. TabItem이 어느 TabFolder에 담길지를 결정하는 부분이다. setText메소드는 각 탭의 헤더 명을 결정한다. 그리고 setControl(Control) 메소드에서 실제 탭 화면의 표시 될 화면 구성요소를 생성하여 넣어준다. (보통 Composite형태로 생성)
1
2
3 |
TabItem tabPage1 = new TabItem(tf, SWT.NONE);
tabPage1.setText("tab1");
tabPage1.setControl(new TabPageComposite1(tf)); |
cs |
TabFolder Method |
기능 |
getItemCount() |
TabFolder의 TabItem 수를 반환한다. |
getItems() |
TabItem 객체 배열을 반환한다. |
getItem(int) |
입력값에 해당하는 TabItem 객체를 반환한다. |
getSelection() |
사용자가 선택한 TabItem을 알려준다. |
setSelection() |
선택될 탭을 설정한다. |
- TabFolder 주요 메소드 -
Example
[CompViewer extends ApplicationWindow]
다른 Override Method는 WindowBuilder에서 자동생성한 부분이니, createContent(Composite parent) 메소드만 집중하여 보면 된다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 |
import org.eclipse.jface.action.MenuManager;
public class CompViewer extends ApplicationWindow {
/**
* Create the application window.
*/
public CompViewer() {
super(null);
createActions();
addToolBar(SWT.FLAT | SWT.WRAP);
addMenuBar();
addStatusLine();
}
/**
* Create contents of the application window.
* @param parent
*/
@Override
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TabFolder tf = new TabFolder(container, SWT.NONE);
TabItem tabPage1 = new TabItem(tf, SWT.NONE);
tabPage1.setText("tab1");
tabPage1.setControl(new TabPageComposite1(tf));
TabItem tabPage2 = new TabItem(tf, SWT.NONE);
tabPage2.setText("tab2");
tabPage2.setControl(new TabPageComposite2(tf));
TabItem tabPage3 = new TabItem(tf, SWT.NONE);
tabPage3.setText("tab3");
tabPage3.setControl(new TabPageComposite3(tf));
tf.pack();
container.pack();
return container;
}
/**
* Create the actions.
*/
private void createActions() {
// Create the actions
}
/**
* Create the menu manager.
* @return the menu manager
*/
@Override
protected MenuManager createMenuManager() {
MenuManager menuManager = new MenuManager("menu");
return menuManager;
}
/**
* Create the toolbar manager.
* @return the toolbar manager
*/
@Override
protected ToolBarManager createToolBarManager(int style) {
ToolBarManager toolBarManager = new ToolBarManager(style);
return toolBarManager;
}
/**
* Create the status line manager.
* @return the status line manager
*/
@Override
protected StatusLineManager createStatusLineManager() {
StatusLineManager statusLineManager = new StatusLineManager();
return statusLineManager;
}
/**
* Launch the application.
* @param args
*/
public static void main(String args[]) {
try {
CompViewer window = new CompViewer();
window.setBlockOnOpen(true);
window.open();
Display.getCurrent().dispose();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Configure the shell.
* @param newShell
*/
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("New Application");
}
/**
* Return the initial size of the window.
*/
@Override
protected Point getInitialSize() {
return new Point(450, 300);
}
}
|
cs |
[TabPageComposite1 extends Composite]
TabPageComposite2, TabPageComposite3 역시 동일하게 구성되어 있다.
간단한 Label을 생성하여 현재 어느 페이지에 위치하여 있는지 표시만 해주고 있다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 |
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
public class TabPageComposite1 extends Composite{
public TabPageComposite1(Composite parent) {
super(parent, SWT.NONE);
this.setBounds(5, 5, 500, 500);
Label label = new Label(this, SWT.NONE);
label.setText("첫 번째 탭 페이지");
label.pack();
}
}
|
cs |
수행결과
다운로드
'프로그래밍 > SWT & JFace' 카테고리의 다른 글
SWT Simple Tree Example (0) | 2016.02.21 |
---|---|
SWT/JFace Layout (0) | 2016.02.15 |
JFace Event처리 (Action and Contribution) (0) | 2016.02.12 |
SWT Event 처리 (Event and Listener) (0) | 2016.02.11 |
화면에 표시되는 주요 클래스 구조 Widget/Control/Composite (0) | 2016.01.17 |
SWT/JFace 기본 동작 구조 (2) | 2016.01.11 |
Hello JFace (0) | 2016.01.06 |
Hello SWT (0) | 2016.01.06 |
이 글을 공유하기