下面列出了javax.swing.border.TitledBorder#setTitleColor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static Component makeTitledPanel(String title, Container cmp, Color bgc) {
JPanel p = new JPanel(new BorderLayout());
if (cmp.getLayout() instanceof BoxLayout) {
p.add(cmp, BorderLayout.NORTH);
} else {
p.add(cmp);
}
if (Objects.nonNull(title)) {
TitledBorder b = BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), title);
if (Objects.nonNull(bgc)) {
b.setTitleColor(new Color(~bgc.getRGB()));
}
p.setBorder(b);
}
if (Objects.nonNull(bgc)) {
p.setOpaque(true);
p.setBackground(bgc);
}
return p;
}
@NotNull
private JComboBox<Speed> speedChooser() {
JPanel panel = new JPanel();
TitledBorder speed = BorderFactory.createTitledBorder("Speed");
speed.setTitleFont(FONT_ITALIC);
speed.setTitleColor(Color.BLUE.darker());
panel.setBorder(speed);
mainPanel.add(panel);
JComboBox<Speed> choose = new JComboBox<>();
choose.setBackground(Color.BLUE.darker());
choose.setForeground(Color.BLUE.darker());
choose.addItem(Speed.FAST);
choose.addItem(Speed.MEDIUM);
choose.addItem(Speed.SLOW);
choose.setSelectedIndex(1);
panel.add(choose);
return choose;
}
public static void addStyle(JTextField textField, String labelName, boolean bottom) {
textField.setHorizontalAlignment(SwingConstants.RIGHT);
Border line = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
TitledBorder titled = BorderFactory.createTitledBorder(line, labelName);
titled.setTitleFont(GraphicsUtils.getFont("Verdana", 0, 13));
titled.setTitleColor(fontColorTitle);
Border empty = null;
if (bottom) {
empty = new EmptyBorder(5, 8, 5, 8);
} else {
empty = new EmptyBorder(5, 8, 0, 8);
}
CompoundBorder border = new CompoundBorder(titled, empty);
textField.setBorder(border);
textField.setForeground(fontColor);
textField.setFont(GraphicsUtils.getFont("Monospaced", 0, 13));
}
public static void addStyle(JScrollPane jScrollPane, String labelName, boolean bottom) {
Border line = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
TitledBorder titled = BorderFactory.createTitledBorder(line, labelName);
titled.setTitleFont(GraphicsUtils.getFont("Verdana", 0, 13));
titled.setTitleColor(fontColorTitle);
Border empty = null;
if (bottom) {
empty = new EmptyBorder(5, 8, 5, 8);
} else {
empty = new EmptyBorder(5, 8, 0, 8);
}
CompoundBorder border = new CompoundBorder(titled, empty);
jScrollPane.setBorder(border);
jScrollPane.setForeground(fontColor);
jScrollPane.setBackground(Color.WHITE);
jScrollPane.setFont(GraphicsUtils.getFont("Monospaced", 0, 13));
jScrollPane.setHorizontalScrollBar(null);
}
private void updateScrollPaneBorder(JPanel panel) {
if (panel == null) {
return;
}
scrollPane.setBackground(panel.getBackground());
if (scrollPane.getVerticalScrollBar().isShowing()) {
TitledBorder titledBorder =
new TitledBorder(BorderFactory.createEmptyBorder(), "(scroll for more options)");
Font font = titledBorder.getTitleFont();
if (font == null) {
// workaround for bug on Java 7
font = titleLabel.getFont();
}
titledBorder.setTitleFont(font.deriveFont(10f));
titledBorder.setTitleColor(Color.BLUE);
titledBorder.setTitlePosition(TitledBorder.BOTTOM);
titledBorder.setTitleJustification(TitledBorder.TRAILING);
scrollPane.setBorder(titledBorder);
}
else {
scrollPane.setBorder(BorderFactory.createEmptyBorder());
}
}
public static void addStyle(JTextArea textArea, String labelName, boolean isBorder) {
Border border = null;
if (isBorder) {
Border line = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
TitledBorder titled = BorderFactory.createTitledBorder(line, labelName);
titled.setTitleFont(GraphicsUtils.getFont("Verdana", 0, 13));
titled.setTitleColor(fontColorTitle);
}
textArea.setBorder(border);
textArea.setForeground(fontColor);
textArea.setFont(GraphicsUtils.getFont("Monospaced", 0, 13));
}
/**
* Check behaviour of method TitledBorder.getTitleColor()
*/
private static void checkTitleColor() {
TitledBorder titledBorder = new TitledBorder(new EmptyBorder(1, 1, 1, 1));
Color defaultColor = UIManager.getLookAndFeelDefaults().getColor("TitledBorder.titleColor");
Color titledBorderColor = titledBorder.getTitleColor();
// check default configuration
if (defaultColor == null) {
if (titledBorderColor == null) {
return;
}
else {
throw new RuntimeException("TitledBorder default color should be null");
}
}
if (!defaultColor.equals(titledBorderColor)) {
throw new RuntimeException("L&F default color " + defaultColor.toString()
+ " differs from TitledBorder color " + titledBorderColor.toString());
}
// title color is explicitly specified
Color color = Color.green;
titledBorder.setTitleColor(color);
if (!color.equals(titledBorder.getTitleColor())) {
throw new RuntimeException("TitledBorder color should be " + color.toString());
}
// title color is unspecified
titledBorder.setTitleColor(null);
if (!defaultColor.equals(titledBorder.getTitleColor())) {
throw new RuntimeException("L&F default color " + defaultColor.toString()
+ " differs from TitledBorder color " + titledBorderColor.toString());
}
}
private void initComponents() {
setLayout(new BorderLayout());
JPanel contentsPanel = new JPanel(new BorderLayout());
contentsPanel.setBackground(UIUtils.getProfilerResultsBackground());
contentsPanel.setOpaque(true);
contentsPanel.setBorder(BorderFactory.createMatteBorder(0, 15, 15, 15, UIUtils.getProfilerResultsBackground()));
headerArea = new HTMLTextArea() {
protected void showURL(URL url) {
String urlString = url.toString();
if (START_LOCATION_URLMASK.equals(urlString)) {
Utils.openLocation(StopwatchProfilingPoint.this.getStartLocation());
} else if (StopwatchProfilingPoint.this.usesEndLocation()) {
Utils.openLocation(StopwatchProfilingPoint.this.getEndLocation());
}
}
};
JScrollPane headerAreaScrollPane = new JScrollPane(headerArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
headerAreaScrollPane.setBorder(BorderFactory.createMatteBorder(0, 0, 15, 0, UIUtils.getProfilerResultsBackground()));
headerAreaScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
contentsPanel.add(headerAreaScrollPane, BorderLayout.NORTH);
dataArea = new HTMLTextArea();
JScrollPane dataAreaScrollPane = new JScrollPane(dataArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
TitledBorder tb = new TitledBorder(Bundle.StopwatchProfilingPoint_DataString());
tb.setTitleFont(Utils.getTitledBorderFont(tb).deriveFont(Font.BOLD));
tb.setTitleColor(javax.swing.UIManager.getColor("Label.foreground")); // NOI18N
dataAreaScrollPane.setBorder(tb);
dataAreaScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
dataAreaScrollPane.setBackground(UIUtils.getProfilerResultsBackground());
contentsPanel.add(dataAreaScrollPane, BorderLayout.CENTER);
add(contentsPanel, BorderLayout.CENTER);
}
public static void addStyle(JComboBox<Object> textField, String labelName) {
Border line = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
TitledBorder titled = BorderFactory.createTitledBorder(line, labelName);
titled.setTitleFont(GraphicsUtils.getFont("Verdana", 0, 13));
titled.setTitleColor(fontColorTitle);
Border empty = new EmptyBorder(0, 8, 0, 8);
CompoundBorder border = new CompoundBorder(titled, empty);
textField.setBorder(border);
textField.setForeground(fontColor);
textField.setFont(GraphicsUtils.getFont("Monospaced", 0, 13));
}
private void initComponents() {
setLayout(new BorderLayout());
JPanel contentsPanel = new JPanel(new BorderLayout());
contentsPanel.setBackground(UIUtils.getProfilerResultsBackground());
contentsPanel.setOpaque(true);
contentsPanel.setBorder(BorderFactory.createMatteBorder(0, 15, 15, 15, UIUtils.getProfilerResultsBackground()));
headerArea = new HTMLTextArea() {
protected void showURL(URL url) {
String urlString = url.toString();
if (START_LOCATION_URLMASK.equals(urlString)) {
Utils.openLocation(LoadGenProfilingPoint.this.getStartLocation());
} else if (LoadGenProfilingPoint.this.usesEndLocation()) {
Utils.openLocation(LoadGenProfilingPoint.this.getEndLocation());
}
}
};
JScrollPane headerAreaScrollPane = new JScrollPane(headerArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
headerAreaScrollPane.setBorder(BorderFactory.createMatteBorder(0, 0, 15, 0, UIUtils.getProfilerResultsBackground()));
headerAreaScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
contentsPanel.add(headerAreaScrollPane, BorderLayout.NORTH);
dataArea = new HTMLTextArea();
JScrollPane dataAreaScrollPane = new JScrollPane(dataArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
TitledBorder tb = new TitledBorder(Bundle.LoadGenProfilingPoint_DataString());
tb.setTitleFont(Utils.getTitledBorderFont(tb).deriveFont(Font.BOLD));
tb.setTitleColor(javax.swing.UIManager.getColor("Label.foreground")); // NOI18N
dataAreaScrollPane.setBorder(tb);
dataAreaScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
dataAreaScrollPane.setBackground(UIUtils.getProfilerResultsBackground());
contentsPanel.add(dataAreaScrollPane, BorderLayout.CENTER);
add(contentsPanel, BorderLayout.CENTER);
}
public static void addStyle(JTextArea textArea, String labelName, boolean isBorder) {
Border border = null;
if (isBorder) {
Border line = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
TitledBorder titled = BorderFactory.createTitledBorder(line, labelName);
titled.setTitleFont(new Font("Verdana", 0, 13));
titled.setTitleColor(new Color(213, 225, 185));
Border empty = new EmptyBorder(5, 8, 5, 8);
CompoundBorder cBorder = new CompoundBorder(titled, empty);
}
textArea.setBorder(border);
textArea.setForeground(new Color(143, 170, 220));
textArea.setFont(new Font("Monospaced", 0, 13));
}
public static void addStyle(JTextField textField, String labelName) {
textField.setHorizontalAlignment(SwingConstants.RIGHT);
Border line = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
TitledBorder titled = BorderFactory.createTitledBorder(line, labelName);
titled.setTitleFont(new Font("Verdana", 0, 13));
titled.setTitleColor(new Color(213, 225, 185));
Border empty = new EmptyBorder(5, 8, 5, 8);
CompoundBorder border = new CompoundBorder(titled, empty);
textField.setBorder(border);
textField.setForeground(new Color(143, 170, 220));
textField.setFont(new Font("Monospaced", 0, 13));
}
/**
* Check behaviour of method TitledBorder.getTitleColor()
*/
private static void checkTitleColor() {
TitledBorder titledBorder = new TitledBorder(new EmptyBorder(1, 1, 1, 1));
Color defaultColor = UIManager.getLookAndFeelDefaults().getColor("TitledBorder.titleColor");
Color titledBorderColor = titledBorder.getTitleColor();
// check default configuration
if (defaultColor == null) {
if (titledBorderColor == null) {
return;
}
else {
throw new RuntimeException("TitledBorder default color should be null");
}
}
if (!defaultColor.equals(titledBorderColor)) {
throw new RuntimeException("L&F default color " + defaultColor.toString()
+ " differs from TitledBorder color " + titledBorderColor.toString());
}
// title color is explicitly specified
Color color = Color.green;
titledBorder.setTitleColor(color);
if (!color.equals(titledBorder.getTitleColor())) {
throw new RuntimeException("TitledBorder color should be " + color.toString());
}
// title color is unspecified
titledBorder.setTitleColor(null);
if (!defaultColor.equals(titledBorder.getTitleColor())) {
throw new RuntimeException("L&F default color " + defaultColor.toString()
+ " differs from TitledBorder color " + titledBorderColor.toString());
}
}
/**
* Check behaviour of method TitledBorder.getTitleColor()
*/
private static void checkTitleColor() {
TitledBorder titledBorder = new TitledBorder(new EmptyBorder(1, 1, 1, 1));
Color defaultColor = UIManager.getLookAndFeelDefaults().getColor("TitledBorder.titleColor");
Color titledBorderColor = titledBorder.getTitleColor();
// check default configuration
if (defaultColor == null) {
if (titledBorderColor == null) {
return;
}
else {
throw new RuntimeException("TitledBorder default color should be null");
}
}
if (!defaultColor.equals(titledBorderColor)) {
throw new RuntimeException("L&F default color " + defaultColor.toString()
+ " differs from TitledBorder color " + titledBorderColor.toString());
}
// title color is explicitly specified
Color color = Color.green;
titledBorder.setTitleColor(color);
if (!color.equals(titledBorder.getTitleColor())) {
throw new RuntimeException("TitledBorder color should be " + color.toString());
}
// title color is unspecified
titledBorder.setTitleColor(null);
if (!defaultColor.equals(titledBorder.getTitleColor())) {
throw new RuntimeException("L&F default color " + defaultColor.toString()
+ " differs from TitledBorder color " + titledBorderColor.toString());
}
}
/**
* Check behaviour of method TitledBorder.getTitleColor()
*/
private static void checkTitleColor() {
TitledBorder titledBorder = new TitledBorder(new EmptyBorder(1, 1, 1, 1));
Color defaultColor = UIManager.getLookAndFeelDefaults().getColor("TitledBorder.titleColor");
Color titledBorderColor = titledBorder.getTitleColor();
// check default configuration
if (defaultColor == null) {
if (titledBorderColor == null) {
return;
}
else {
throw new RuntimeException("TitledBorder default color should be null");
}
}
if (!defaultColor.equals(titledBorderColor)) {
throw new RuntimeException("L&F default color " + defaultColor.toString()
+ " differs from TitledBorder color " + titledBorderColor.toString());
}
// title color is explicitly specified
Color color = Color.green;
titledBorder.setTitleColor(color);
if (!color.equals(titledBorder.getTitleColor())) {
throw new RuntimeException("TitledBorder color should be " + color.toString());
}
// title color is unspecified
titledBorder.setTitleColor(null);
if (!defaultColor.equals(titledBorder.getTitleColor())) {
throw new RuntimeException("L&F default color " + defaultColor.toString()
+ " differs from TitledBorder color " + titledBorderColor.toString());
}
}
private static TitledBorder createBorder(String title) {
TitledBorder border = BorderFactory.createTitledBorder(title);
border.setTitleColor(ColorPalette.FOREGROUND_COLOR);
border.setTitleFont(Fonts.FONT);
return border;
}
private void initComponents() {
setLayout(new BorderLayout());
JPanel contentsPanel = new JPanel(new BorderLayout());
contentsPanel.setBackground(UIUtils.getProfilerResultsBackground());
contentsPanel.setOpaque(true);
contentsPanel.setBorder(BorderFactory.createMatteBorder(0, 15, 15, 15, UIUtils.getProfilerResultsBackground()));
headerArea = new HTMLTextArea();
JScrollPane headerAreaScrollPane = new JScrollPane(headerArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
headerAreaScrollPane.setBorder(BorderFactory.createMatteBorder(0, 0, 15, 0, UIUtils.getProfilerResultsBackground()));
headerAreaScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
contentsPanel.add(headerAreaScrollPane, BorderLayout.NORTH);
dataArea = new HTMLTextArea() {
protected void showURL(URL url) {
File resolvedFile = null;
try {
resolvedFile = new File(url.toURI());
} catch (URISyntaxException ex) {
ex.printStackTrace();
}
final File snapshotFile = resolvedFile;
if ((snapshotFile != null) && snapshotFile.exists()) {
String type = TimedTakeSnapshotProfilingPoint.this.getSnapshotType();
if (type.equals(TYPE_PROFDATA_KEY) || type.equals(TYPE_HEAPDUMP_KEY)) {
ResultsManager.getDefault().openSnapshot(snapshotFile);
}
} else {
ProfilerDialogs.displayWarning(
Bundle.TimedTakeSnapshotProfilingPoint_SnapshotNotAvailableMsg());
}
}
};
JScrollPane dataAreaScrollPane = new JScrollPane(dataArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
TitledBorder tb = new TitledBorder(Bundle.TimedTakeSnapshotProfilingPoint_DataString());
tb.setTitleFont(Utils.getTitledBorderFont(tb).deriveFont(Font.BOLD));
tb.setTitleColor(javax.swing.UIManager.getColor("Label.foreground")); // NOI18N
dataAreaScrollPane.setBorder(tb);
dataAreaScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
dataAreaScrollPane.setBackground(UIUtils.getProfilerResultsBackground());
contentsPanel.add(dataAreaScrollPane, BorderLayout.CENTER);
add(contentsPanel, BorderLayout.CENTER);
}
private void initComponents() {
setLayout(new BorderLayout());
JPanel contentsPanel = new JPanel(new BorderLayout());
contentsPanel.setBackground(UIUtils.getProfilerResultsBackground());
contentsPanel.setOpaque(true);
contentsPanel.setBorder(BorderFactory.createMatteBorder(0, 15, 15, 15, UIUtils.getProfilerResultsBackground()));
headerArea = new HTMLTextArea() {
protected void showURL(URL url) {
Utils.openLocation(TakeSnapshotProfilingPoint.this.getLocation());
}
};
JScrollPane headerAreaScrollPane = new JScrollPane(headerArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
headerAreaScrollPane.setBorder(BorderFactory.createMatteBorder(0, 0, 15, 0, UIUtils.getProfilerResultsBackground()));
headerAreaScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
contentsPanel.add(headerAreaScrollPane, BorderLayout.NORTH);
dataArea = new HTMLTextArea() {
protected void showURL(URL url) {
File resolvedFile = null;
try {
resolvedFile = new File(url.toURI());
} catch (URISyntaxException ex) {
ex.printStackTrace();
}
final File snapshotFile = resolvedFile;
if ((snapshotFile != null) && snapshotFile.exists()) {
String type = TakeSnapshotProfilingPoint.this.getSnapshotType();
if (type.equals(TYPE_PROFDATA_KEY) || type.equals(TYPE_HEAPDUMP_KEY)) {
ResultsManager.getDefault().openSnapshot(snapshotFile);
}
} else {
ProfilerDialogs.displayWarning(
Bundle.TakeSnapshotProfilingPoint_SnapshotNotAvailableMsg());
}
}
};
JScrollPane dataAreaScrollPane = new JScrollPane(dataArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
TitledBorder tb = new TitledBorder(Bundle.TakeSnapshotProfilingPoint_DataString());
tb.setTitleFont(Utils.getTitledBorderFont(tb).deriveFont(Font.BOLD));
tb.setTitleColor(javax.swing.UIManager.getColor("Label.foreground")); // NOI18N
dataAreaScrollPane.setBorder(tb);
dataAreaScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
dataAreaScrollPane.setBackground(UIUtils.getProfilerResultsBackground());
contentsPanel.add(dataAreaScrollPane, BorderLayout.CENTER);
add(contentsPanel, BorderLayout.CENTER);
}
public static Border getTitleBorder(String title){
TitledBorder border = new TitledBorder(new EtchedBorder(), title);
border.setTitleColor(UIConsts.DARK_GREEN);
return border;
}
protected TitledBorder createTitileBorder(String title) {
TitledBorder titledBorder = new TitledBorder(title);
titledBorder.setTitleColor(Color.BLUE.darker());
return titledBorder;
}