-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTextLineNumberDemo.java
More file actions
65 lines (53 loc) · 2.31 KB
/
TextLineNumberDemo.java
File metadata and controls
65 lines (53 loc) · 2.31 KB
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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class TextLineNumberTest
{
public static void main(String[] args)
{
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(10,20,20,20));
panel.setLayout(new BorderLayout());
String text =
"Typically the same font would be used for the entire text component.\n\n" +
"However, this component now supports multiple fonts and font sizes.\n\n" +
"Test it out using the buttons below.\n";
// String text =
// "<html>line1<br>line2<br>line3<br></html>";
final JTextPane textPane = new JTextPane();
// textPane.setContentType("text/html");
// final JTextArea textPane = new JTextArea();
// textPane.setLineWrap(true);
// textPane.setFont( new Font("monospaced", Font.PLAIN, 36) );
textPane.setText(text);
JScrollPane scrollPane = new JScrollPane(textPane);
panel.add(scrollPane);
scrollPane.setPreferredSize(new Dimension(300, 250));
TextLineNumber lineNumber = new TextLineNumber(textPane, 3);
// lineNumber.setUpdateFont(true);
lineNumber.setUpdateFont(false);
float fontSize = textPane.getFont().getSize() - 6;
Font font = textPane.getFont().deriveFont( fontSize );
// lineNumber.setFont(font);
// lineNumber.setBorderGap(20);
// lineNumber.setForeground(Color.ORANGE);
// lineNumber.setDigitAlignment(TextLineNumber.LEFT);
// float fontSize = component.getFont().getSize() - 0.0f;
// componentFont = component.getFont().deriveFont( fontSize );
scrollPane.setRowHeaderView( lineNumber );
JPanel buttons = new JPanel( new FlowLayout(FlowLayout.CENTER, 5, 5) );
buttons.add( new JButton(new StyledEditorKit.FontSizeAction("Font 12", 12)));
buttons.add( new JButton(new StyledEditorKit.FontSizeAction("Font 16", 16)));
buttons.add( new JButton(new StyledEditorKit.FontSizeAction("Font 20", 20)));
buttons.add( new JButton(new StyledEditorKit.FontSizeAction("Font 24", 24)));
panel.add(buttons, BorderLayout.SOUTH);
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Text Component Line Number");
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setContentPane( panel );
frame.setSize(500, 240);
frame.setLocationRelativeTo( null );
frame.setVisible(true);
}
}