Java Reference
In-Depth Information
1
JComboBox fieldCombo =
new
JComboBox
()
;
2
JScrollPane scrollPane =
new
JScrollPane
()
;
3
JTextPane textPane =
new
JTextPane
()
;
4
String
title
[]
=
{
Oz"
}
;
"Casablanca"
,
"Citizen Kane"
,
"Singin' in the Rain"
,
"The Wizard of
5
6
public
DVD
()
7
{
8
super
(
"Classics on DVD"
)
;
9
}
10
11
public
JMenuBar createMenuBar
()
12
{
13
JMenuBar mnuBar =
new
JMenuBar
()
;
14
setJMenuBar
(
mnuBar
)
;
15
JMenu mnuFile =
new
JMenu
(
"File"
,
true
)
;
16
mnuFile.setDisplayedMnemonicIndex
(
0
)
;
17
mnuBar.add
(
mnuFile
)
;
18
return
mnuBar;
19
}
20
21
public
Container
createContentPane
()
22
{
23
fieldCombo.addItem
(
"Title"
)
;
24
fieldCombo.addItem
(
"Studio"
)
;
25
fieldCombo.setToolTipText
(
"Click the drop-down arrow to display sort fields."
)
;
26
JPanel centerPanel =
new
JPanel
()
;
27
setTabsAndStyles
(
textPane
)
;
28
JTextPane internalTextPane = addTextToTextPane
()
;
29
JScrollPane paneScrollPane =
new
JScrollPane
(
internalTextPane
)
;
30
centerPanel.add
(
paneScrollPane
)
;
31
Container
c = getContentPane
()
;
32
c.setLayout
(
new
BorderLayout
(
10,10
))
;
33
c.add
(
centerPanel,
BorderLayout
.CENTER
)
;
34
return
c;
35
}
36
37
protected void
setTabsAndStyles
(
JTextPane textPane
)
38
{
39
TabStop tab =
new
TabStop
(
200, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE
)
;
40
TabSet tabset =
new
TabSet
(
tab
)
;
41
Style fontStyle =
42
StyleContext.getDefaultStyleContext
()
.getStyle
(
StyleContext.DEFAULT_STYLE
)
;
43
StyleConstants.setFontFamily
(
fontStyle,
"SansSerif"
)
;
44
45
}
46
47
public
JTextPane addTextToTextPane
()
48
{
49
Document doc = textPane.getDocument
()
;
50
try
51
{
52
doc.remove
(
0,doc.getLength
())
;
53
doc.insertString
(
0,
"TITLE\tSTUDIO\tYEAR\n"
,textPane.getStyle
(
"large"
))
;
54
}
55
catch
(
BadLocationException ble
)
56
{
57
}
58
return
textPane;
59
}
60
61
public static void
main
(
String
args
[])
62
{
63
DVD f =
new
DVD
()
;
64
f.setDefaultCloseOperation
(
JFrame.EXIT_ON_CLOSE
)
;
65
f.setJMenuBar
(
f.createMenuBar
())
;
66
f.setContentPane f.createContentPane
())
;
67
f.setSize
(
600,375
)
;
68
f.setVisible
(
true
)
;
69
}
FIGURE 7-50
Search WWH ::
Custom Search