下面列出了javax.swing.JToggleButton#setFont ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private WebButtonPopup generatePopupMenu() {
WebButtonPopup pm = new WebButtonPopup(this, PopupWay.downCenter);
JPanel list = new JPanel(new GridLayout(7, 1));
for (Entry<String, Integer> acc : otherTypes.entrySet()) {
JToggleButton jtb = new JToggleButton(
acc.getKey().substring(0, 1).toUpperCase() + acc.getKey().substring(1, Math.min(acc.getKey().length(), 7)));
jtb.setSelected((visibility & acc.getValue()) != 0);
jtb.addActionListener(e -> {
if ((visibility & acc.getValue()) != 0) {
visibility -= acc.getValue();
} else {
visibility |= acc.getValue();
}
});
jtb.setFont(new Font(jtb.getFont().getName(), Font.PLAIN, 10));
list.add(jtb);
}
pm.setContent(list);
return pm;
}
@Override
public void actionPerformed(ActionEvent e) {
for (JToggleButton button : primaryButtons) {
if (button != e.getSource() && button.isSelected()) {
button.setSelected(false);
} else if (button == e.getSource() && !button.isSelected()) {
button.setSelected(true);
}
if (button.isSelected()) {
button.setFont(button.getFont().deriveFont(Font.BOLD));
} else {
button.setFont(button.getFont().deriveFont(Font.PLAIN));
}
}
if (secondaryButton != null) {
if (secondaryButton != e.getSource() && secondaryButton.isSelected()) {
secondaryButton.clearMenuSelection();
}
}
}
protected void installComponents() {
if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
iconPane = new JToggleButton(frame.getTitle(), frame.getFrameIcon()) {
public String getToolTipText() {
return getText();
}
public JPopupMenu getComponentPopupMenu() {
return frame.getComponentPopupMenu();
}
};
ToolTipManager.sharedInstance().registerComponent(iconPane);
iconPane.setFont(desktopIcon.getFont());
iconPane.setBackground(desktopIcon.getBackground());
iconPane.setForeground(desktopIcon.getForeground());
} else {
iconPane = new SeaGlassInternalFrameTitlePane(frame);
iconPane.setName("InternalFrame.northPane");
}
desktopIcon.setLayout(new BorderLayout());
desktopIcon.add(iconPane, BorderLayout.CENTER);
}
private JToggleButton createToggleButton(String toolTipText,
ImageIcon icon,
java.awt.event.ActionListener actionListener)
{
JToggleButton btn = new JToggleButton();
btn.setMargin(new Insets(0, 0, 0, 0));
btn.setPreferredSize(new Dimension(30, 30));
btn.setIcon(icon);
btn.setMinimumSize(new Dimension(30, 30));
btn.setVerticalTextPosition(SwingConstants.BOTTOM);
btn.setSelected(false);
btn.setToolTipText(toolTipText);
btn.setHorizontalTextPosition(SwingConstants.CENTER);
btn.setFont(new java.awt.Font("SansSerif", 0, 10));
btn.setMaximumSize(new Dimension(30, 30));
btn.addActionListener(actionListener);
return btn;
}
private void toggleView(java.awt.event.ItemEvent evt) {
JToggleButton toggleButton = ((JToggleButton) evt.getSource());
if (evt.getStateChange() == ItemEvent.SELECTED) {
toggleButton.setFont(toggleButton.getFont().deriveFont(Font.BOLD));
String text = toggleButton.getText();
CardLayout layout = (CardLayout) cardPanel.getLayout();
layout.show(cardPanel, text);
} else {
toggleButton.setFont(toggleButton.getFont().deriveFont(Font.PLAIN));
}
}
/**
* Called when a waypoint is added. This implementation adds a waypoint button.
* @param graphic the waypoint graphic, whose ID may or may not be populated.
* @param graphicUid the waypoint graphic's ID.
* @see RouteListener#waypointAdded(com.esri.core.map.Graphic, int)
*/
public void waypointAdded(Graphic graphic, int graphicUid) {
final JToggleButton button = new JToggleButton((String) graphic.getAttributeValue("name"));
waypointButtonToGraphicId.put(button, graphicUid);
graphicIdToWaypointButton.put(graphicUid, button);
Font font = new Font("Arial", Font.PLAIN, 18);
button.setFont(font);
button.setFocusable(false);
button.setSelected(false);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (button == selectedWaypointButton) {
//Unselect
buttonGroup_waypoints.remove(button);
button.setSelected(false);
buttonGroup_waypoints.add(button);
selectedWaypointButton = null;
routeController.setSelectedWaypoint(null);
} else {
selectedWaypointButton = button;
routeController.setSelectedWaypoint(waypointButtonToGraphicId.get(button));
}
}
});
button.setMaximumSize(new Dimension(Integer.MAX_VALUE, 60));
button.setMinimumSize(new Dimension(0, 60));
jPanel_waypointsList.add(button);
buttonGroup_waypoints.add(button);
}