下面列出了javax.swing.JLabel#getFont ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Creates a panel with a heading.
*
* @param labelText
* The text for the heading
*
* @return The panel
*/
private JPanel createSubGroupPanel(String labelText) {
JLabel subGroupLabel = new JLabel();
Font font = subGroupLabel.getFont();
font = font.deriveFont(Font.BOLD, 14f);
subGroupLabel.setFont(font);
subGroupLabel.setForeground(SettingsTabs.COLOR_SUBGROUP);
subGroupLabel.setText(labelText);
int top = SUBGROUP_TOP_MARGIN;
if (isFirstSubGroup) {
isFirstSubGroup = false;
top = FIRST_SUBGROUP_TOP_MARGIN;
}
subGroupLabel.setBorder(BorderFactory.createEmptyBorder(top, 0, 7, 0));
JPanel subGroupPanel = new JPanel();
subGroupPanel.setLayout(new BoxLayout(subGroupPanel, BoxLayout.LINE_AXIS));
subGroupPanel.add(subGroupLabel);
subGroupPanel.add(Box.createHorizontalGlue());
return subGroupPanel;
}
private void addYayLabel() {
logger.info("Adding yay label. @SuccessfulSubmissionDialog");
JLabel yayLabel = new JLabel("All tests passed on the server.");
Font font = yayLabel.getFont();
font = font.deriveFont(Font.BOLD, font.getSize2D() * 1.2f);
yayLabel.setFont(font);
yayLabel.setForeground(new JBColor(new Color(0, 153, 51), new Color(0, 153, 51)));
yayLabel.setIcon(TmcIcons.SUCCESS);
// URL imageUrl = new URL("/fi/helsinki/cs/tmc/intellij/smile.gif");
// ImageIcon icon = new ImageIcon(getClass().getResource("/smiley.gif"));
// yayLabel.setIcon(icon);
// new ImageIcon(getClass().getResource("/fi/helsinki/cs/tmc/smile.gif"));
// yayLabel.setIcon(ConvenientDialogDisplayer.getDefault().getSmileyIcon());
getContentPane().add(leftAligned(yayLabel));
}
public AboutDialog(JFrame parent, String applicationName, String description, String version, String wpilibVersion) {
super(parent, applicationName);
Box aboutWindow = new Box(BoxLayout.Y_AXIS);
JLabel productName = new JLabel(applicationName);
Font defaultFont = productName.getFont();
productName.setFont(new Font(defaultFont.getName(), Font.BOLD, defaultFont.getSize() + 8));
aboutWindow.add(Box.createVerticalStrut(10));
aboutWindow.add(productName);
aboutWindow.add(new JLabel("Version " + version));
aboutWindow.add(Box.createVerticalStrut(15));
aboutWindow.add(new JLabel("Exports to WPILib Version " + wpilibVersion));
aboutWindow.add(Box.createVerticalStrut(15));
aboutWindow.add(new JLabel(description));
aboutWindow.add(Box.createVerticalStrut(15));
aboutWindow.add(new JLabel("FIRST/WPI Robotics Research Group"));
aboutWindow.add(Box.createVerticalStrut(5));
ButtonBox buttonBox = new ButtonBox(BoxLayout.X_AXIS);
JButton okButton = new JButton("OK");
this.getRootPane().setDefaultButton(okButton);
okButton.addActionListener(e -> setVisible(false));
buttonBox.add(okButton);
aboutWindow.add(buttonBox);
this.getContentPane().add(aboutWindow, "Center");
this.pack();
}
/**
* Create the logo area.
* @return the {@link JComponent} enclosing the text area.
*/
private static JComponent createLogoPanel() {
final JPanel logoPanel = new JPanel();
logoPanel.setBackground(BKG);
logoPanel.setLayout(new BoxLayout(logoPanel, BoxLayout.Y_AXIS));
// add the JPPF logo
logoPanel.add(new JLabel(GuiUtils.loadIcon("/jppf_logo.gif")));
// add a formatted text just below the logo
final JLabel label = new JLabel("JPPF pluggable view");
label.setForeground(new Color(109, 120, 182));
final Font font = label.getFont();
label.setFont(new Font("Arial", Font.BOLD, 2*font.getSize()));
logoPanel.add(label);
return logoPanel;
}
private static JLabel createSliderLabel(String text) {
JLabel label = new JLabel(text);
Font oldFont = label.getFont();
Font newFont = oldFont.deriveFont(oldFont.getSize2D() * 0.85f);
label.setFont(newFont);
return label;
}
static JLabel createHeaderLabel(String label, String ad, Component comp) {
JLabel jl = new JLabel();
Mnemonics.setLocalizedText(jl, label);
Font labelFont = jl.getFont();
Font boldFont = labelFont.deriveFont(Font.BOLD);
jl.setFont(boldFont);
if (ad != null)
jl.getAccessibleContext().setAccessibleDescription(ad);
if (comp != null)
jl.setLabelFor(comp);
return jl;
}
private JLabel createSliderLabel(String text) {
JLabel label = new JLabel(text);
Font oldFont = label.getFont();
Font newFont = oldFont.deriveFont(oldFont.getSize2D() * 0.85f);
label.setFont(newFont);
return label;
}
private void createTileLabel(TileType type) {
Tile tile = new Tile(type);
JLabel label = new JLabel(tile.getScaledIcon(TILE_SIZE));
label.setToolTipText(CLICK_TO_ROTATE + type.readableRepresentation());
Font font = label.getFont();
label.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
label.addMouseListener((MouseClickListener) event -> {
tile.rotateRight();
label.setIcon(tile.getScaledIcon(TILE_SIZE));
});
add(label, BorderLayout.NORTH);
}
@SuppressWarnings("unchecked")
public static JLabel toLinkText(JLabel label) {
label.setForeground(StyleConstants.LINK_COLOR);
Font font = label.getFont();
Map<TextAttribute, Object> attributes = (Map<TextAttribute, Object>) font.getAttributes();
attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
label.setFont(font.deriveFont(attributes));
return label;
}
protected void paintText(Graphics2D g, JLabel label, String text,
boolean isSelected, boolean isIndicated) {
Font font = label.getFont();
g.setFont(font);
FontMetrics metrics = g.getFontMetrics(font);
int limit = text.length();
Rectangle2D r = g.getFontMetrics().getStringBounds(text, g);
String finalText = text;
while (limit > 0 && r.getWidth() > textRect.width) {
limit--;
finalText = text.substring(0, limit) + "...";
r = g.getFontMetrics().getStringBounds(finalText, g);
}
g.drawString(finalText, textRect.x, textRect.y + metrics.getAscent());
}
private JLabel getLinkJLabel(String caption) {
JLabel ret = new JLabel("<html><u>" + caption + "</u></html>");
Font oldFont = ret.getFont();
ret.setFont(new Font(oldFont.getName(),
oldFont.getStyle() &~ Font.BOLD, oldFont.getSize() ));
ret.setForeground(Color.BLUE);
ret.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
ret.addMouseListener(this);
return ret;
}
/** Creates the UI. */
private void createUI() {
JLabel label =
new JLabel(
Localisation.getString(
DataSourceConnectorEmpty.class,
"DataSourceConnectorEmpty.internalDataSource"));
Font font = label.getFont();
Font f = new Font(font.getName(), font.getStyle(), 24);
label.setFont(f);
panel.add(label);
}
/** Adds a customized heading to the specified panel. */
void addHeaderLabel(final JPanel p, final String label) {
final JLabel lbl = new JLabel(label);
lbl.setForeground(Color.DARK_GRAY);
lbl.setBorder(new EmptyBorder(10, 3, 0, 0));
final Font lblFont = lbl.getFont();
lbl.setFont(lblFont.deriveFont((float) (lblFont.getSize() - 1.5)));
p.add(lbl);
}
public InjectedParameterPlaceholderLabel(ConnectionParameterModel param) {
super(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
JLabel icon = new JLabel("", INJECTED_ICON, JLabel.LEFT);
add(icon, gbc);
Font font = icon.getFont();
String bodyRule = "body { font-family: " + font.getFamily() + "; " +
"font-size: " + font.getSize() + "pt; }";
((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule);
editorPane.setOpaque(false);
editorPane.setBorder(null);
editorPane.setEditable(false);
editorPane.addHyperlinkListener(event -> {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED && event.getURL() != null) {
RMUrlHandler.openInBrowser(event.getURL());
}
});
gbc.insets.left = icon.getIconTextGap();
gbc.weightx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
add(editorPane, gbc);
valueProviderChanged = (i, o, n) -> updateText(param);
valueProviderParameterChanged = c -> {
while (c.next()) {
for (ValueProviderParameterModel valueProviderParameterModel : c.getAddedSubList()) {
valueProviderParameterModel.valueProperty().removeListener(valueProviderChanged);
valueProviderParameterModel.valueProperty().addListener(valueProviderChanged);
}
}
updateText(param);
};
param.injectorNameProperty().addListener((i, o, n) -> registerListener(param));
registerListener(param);
}
public SnapAboutBox() {
super(new BorderLayout(4, 4));
ModuleInfo desktopModuleInfo = Modules.getDefault().ownerOf(SnapAboutBox.class);
engineModuleInfo = Modules.getDefault().ownerOf(Product.class);
ImageIcon image = new ImageIcon(SnapAboutBox.class.getResource("SNAP_Banner.jpg"));
JLabel banner = new JLabel(image);
versionText = new JLabel("<html><b>SNAP " + SystemUtils.getReleaseVersion() + "</b>");
JLabel infoText = new JLabel("<html>"
+ "This program is free software: you can redistribute it and/or modify it<br>"
+ "under the terms of the <b>GNU General Public License</b> as published by<br>"
+ "the Free Software Foundation, either version 3 of the License, or<br>"
+ "(at your option) any later version.<br>"
+ "<br>"
+ "<b>SNAP Desktop implementation version: </b>" + desktopModuleInfo.getImplementationVersion() + "<br>"
+ "<b>SNAP Engine implementation version: </b>" + engineModuleInfo.getImplementationVersion() + "<br>"
/*
+ "<b>Home directory: </b>" + SystemUtils.getApplicationHomeDir() + "<br>"
+ "<b>User directory: </b>" + SystemUtils.getApplicationDataDir() + "<br>"
+ "<b>Cache directory: </b>" + SystemUtils.getCacheDir() + "<br>"
*/
+ "<b>JRE: </b>" + System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version") + "<br>"
+ "<b>JVM: </b>" + System.getProperty("java.vm.name") + " by " + System.getProperty("java.vendor") + "<br>"
+ "<b>Memory: </b>" + Math.round(Runtime.getRuntime().maxMemory() / 1024. / 1024.) + " MiB<br>"
);
Font font = versionText.getFont();
if (font != null) {
infoText.setFont(font.deriveFont(font.getSize() * 0.9f));
}
JPanel innerPanel = new JPanel(new BorderLayout(4, 4));
innerPanel.setBorder(new EmptyBorder(8, 4, 8, 4));
innerPanel.add(createVersionPanel(), BorderLayout.NORTH);
innerPanel.add(infoText, BorderLayout.SOUTH);
JPanel bannerPanel = new JPanel(new BorderLayout(4, 4));
bannerPanel.setBorder(new EmptyBorder(4, 4, 4, 4));
bannerPanel.add(banner);
add(bannerPanel, BorderLayout.WEST);
add(innerPanel, BorderLayout.CENTER);
/*
final Properties properties = System.getProperties();
for (String name : properties.stringPropertyNames()) {
System.out.println(name + " = " + properties.getProperty(name));
}
*/
}
public ReprocessedSeparatorTableCell(final JTable jTable, final SeparatorList<ReprocessedInterface> separatorList, final ActionListener actionListener) {
super(jTable, separatorList);
jColor = new JLabel();
jColor.setOpaque(true);
jColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
jRemove = new JButton(TabsReprocessed.get().remove());
jRemove.setOpaque(false);
jRemove.setActionCommand(ReprocessedCellAction.REMOVE.name());
jRemove.addActionListener(actionListener);
jName = new JLabel();
Font font = jName.getFont();
jName.setFont(new Font(font.getName(), Font.BOLD, font.getSize() + 1));
JLabel jSellPriceLabel = new JLabel(TabsReprocessed.get().price());
jSellPriceLabel.setFont(new Font(font.getName(), Font.BOLD, font.getSize()));
jPrice = new JLabel();
jBatchSizeLabel = new JLabel(TabsReprocessed.get().batch());
jBatchSizeLabel.setFont(new Font(font.getName(), Font.BOLD, font.getSize()));
jBatchSize = new JLabel();
jValueLabel = new JLabel(TabsReprocessed.get().value());
jValueLabel.setFont(new Font(font.getName(), Font.BOLD, font.getSize()));
jValue = new JLabel();
layout.setHorizontalGroup(
layout.createSequentialGroup()
.addComponent(jExpand)
.addGap(5)
.addComponent(jColor, Program.getButtonsHeight() - 6, Program.getButtonsHeight() - 6, Program.getButtonsHeight() - 6)
.addGap(10)
.addComponent(jRemove, Program.getButtonsWidth(), Program.getButtonsWidth(), Program.getButtonsWidth())
.addGap(10)
//.addComponent(jNameLabel)
//.addGap(5)
.addComponent(jName, 220, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(10)
.addComponent(jSellPriceLabel)
.addGap(5)
.addComponent(jPrice)
.addGap(10)
.addComponent(jValueLabel)
.addGap(5)
.addComponent(jValue)
.addGap(10)
.addComponent(jBatchSizeLabel)
.addGap(5)
.addComponent(jBatchSize)
);
layout.setVerticalGroup(
layout.createSequentialGroup()
.addGap(2)
.addGroup(layout.createParallelGroup()
.addComponent(jExpand, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
.addGroup(layout.createSequentialGroup()
.addGap(3)
.addComponent(jColor, Program.getButtonsHeight() - 6, Program.getButtonsHeight() - 6, Program.getButtonsHeight() - 6)
)
.addComponent(jRemove, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
//.addComponent(jNameLabel, Program.BUTTONS_HEIGHT, Program.BUTTONS_HEIGHT, Program.BUTTONS_HEIGHT)
.addComponent(jName, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
.addComponent(jSellPriceLabel, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
.addComponent(jPrice, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
.addComponent(jValueLabel, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
.addComponent(jValue, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
.addComponent(jBatchSizeLabel, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
.addComponent(jBatchSize, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
)
.addGap(2)
);
}
/** Constructs a preview pane for the given file chooser. */
public PreviewPane(final Context context, final JFileChooser jc) {
super();
context.inject(this);
// create view
setBorder(new EmptyBorder(0, 10, 0, 10));
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
iconLabel = new JLabel();
iconLabel.setMinimumSize(new java.awt.Dimension(128, -1));
iconLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
add(iconLabel);
add(Box.createVerticalStrut(7));
formatLabel = new JLabel();
formatLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
add(formatLabel);
add(Box.createVerticalStrut(5));
resLabel = new JLabel();
resLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
add(resLabel);
zctLabel = new JLabel();
zctLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
add(zctLabel);
typeLabel = new JLabel();
typeLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
add(typeLabel);
// smaller font for most labels
Font font = formatLabel.getFont();
font = font.deriveFont(font.getSize2D() - 3);
formatLabel.setFont(font);
resLabel.setFont(font);
zctLabel.setFont(font);
typeLabel.setFont(font);
// populate model
icon = null;
iconText = formatText = resText = npText = typeText = "";
iconTip = formatTip = resTip = zctTip = typeTip = null;
if (jc != null) {
jc.setAccessory(this);
jc.addPropertyChangeListener(this);
refresher = new Runnable() {
@Override
public void run() {
iconLabel.setIcon(icon);
iconLabel.setText(iconText);
iconLabel.setToolTipText(iconTip);
formatLabel.setText(formatText);
formatLabel.setToolTipText(formatTip);
resLabel.setText(resText);
resLabel.setToolTipText(resTip);
zctLabel.setText(npText);
zctLabel.setToolTipText(zctTip);
typeLabel.setText(typeText);
typeLabel.setToolTipText(typeTip);
}
};
// start separate loader thread
loaderAlive = true;
loader = new Thread(this, "Preview");
loader.start();
}
}
private JComponent createHeader( String title ) {
JLabel label = createLabel( title );
Font defaultFont = label.getFont();
label.setFont( defaultFont.deriveFont( Font.BOLD ).deriveFont( defaultFont.getSize2D()+2.0f ));
return label;
}
private void createContent() {
Container cp = (JComponent) getContentPane();
final JPanel urlPanel = new JPanel(new BorderLayout(0, 12));
urlPanel.setBorder(new EmptyBorder(6, 12, 12, 12));
final JPanel bottomPanel = new JPanel(new BorderLayout());
statusBar = new JLabel(" ", JLabel.CENTER);
final Font normalLabelFont = statusBar.getFont();
Font boldLabelFont = normalLabelFont.deriveFont(Font.BOLD);
final Font smallLabelFont = normalLabelFont.deriveFont(normalLabelFont.getSize2D() - 1);
//TODO: is this fine or should it be padded like original?
final URL iconURL = GuiMain.class.getResource("/icon/wildfly_logo.png");
final Image logo = Toolkit.getDefaultToolkit().getImage(iconURL);
final Icon icon = new ImageIcon(logo);
final JLabel mastheadLabel = new JLabel(icon);
cp.add(mastheadLabel, NORTH);
cp.add(urlPanel, CENTER);
cp.add(bottomPanel, SOUTH);
tfURL = new JTextField();
tfURL.getDocument().addDocumentListener(new UrlDocumentListener(tfURL));
tfURL.setPreferredSize(tfURL.getPreferredSize());
final JPanel tfPanel = new JPanel(new BorderLayout());
urlPanel.add(tfPanel, CENTER);
tfPanel.add(tfURL, NORTH);
final JLabel remoteMessageLabel = new JLabel(HINT_CONNECT);
remoteMessageLabel.setFont(smallLabelFont);
remoteMessageLabel.setForeground(hintTextColor);
tfPanel.add(remoteMessageLabel, CENTER);
final JPanel userPwdPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
userPwdPanel.setBorder(new EmptyBorder(12, 0, 0, 0)); // top padding
int tfWidth = IS_WIN ? 12 : 8;
tfUserName = new JTextField(tfWidth);
JPanel lc;
lc = new Labeled(TEXT_USERNAME,boldLabelFont, tfUserName);
userPwdPanel.add(lc);
tfPassword = new JPasswordField(tfWidth);
// Heights differ, so fix here
tfPassword.setPreferredSize(tfUserName.getPreferredSize());
lc = new Labeled(TEXT_PASSWORD, boldLabelFont, tfPassword);
lc.setBorder(new EmptyBorder(0, 12, 0, 0)); // Left padding
lc.setFont(boldLabelFont);
userPwdPanel.add(lc);
tfPanel.add(userPwdPanel, SOUTH);
final JButton connectButton = new JButton(this.actionConnect);
connectButton.setToolTipText(HINT_CONNECT_BUTTON);
final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
buttonPanel.setBorder(new EmptyBorder(12, 12, 2, 12));
buttonPanel.add(connectButton);
bottomPanel.add(buttonPanel, NORTH);
bottomPanel.add(statusBar, SOUTH);
this.pack();
}
private void makeFontBigger(JLabel titleLabel) {
Font current = titleLabel.getFont();
Font biggerFont = current.deriveFont(current.getSize() + 4f);
titleLabel.setFont(biggerFont);
}