下面列出了javax.swing.AbstractButton#setFocusPainted ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Temporarily massage this component so it is visible, enabled, unselected,
* unfocused, etc.
*/
private void storeState(JComponent c) {
if (c instanceof AbstractButton) {
AbstractButton b = (AbstractButton) c;
b.putClientProperty(WAS_SELECTED, new Boolean(b.isSelected()));
b.putClientProperty(WAS_FOCUS_PAINTED, new Boolean(b.isSelected()));
b.setSelected(false);
b.setFocusPainted(false);
}
if (c.isEnabled() == false) {
c.putClientProperty(WAS_ENABLED, new Boolean(c.isEnabled()));
c.setEnabled(true);
}
if (c.isVisible() == false) {
c.putClientProperty(WAS_VISIBLE, new Boolean(c.isVisible()));
c.setVisible(true);
}
for (int a = 0; a < c.getComponentCount(); a++) {
if (c.getComponent(a) instanceof JComponent) {
storeState((JComponent) c.getComponent(a));
}
}
}
protected Insets prepareButton(AbstractButton b) {
if (b.isFocusPainted()) {
// if painting the focus makes a button larger: then we need
// to acknowledge that so the getInsets method still
// right-aligns our labels and checkboxes correctly.
Dimension d1 = b.getPreferredSize();
b.setFocusPainted(false);
Dimension d2 = b.getPreferredSize();
b.setFocusPainted(true);
Insets negativeInsets = new Insets(0, 0, d2.width - d1.width,
d2.height - d1.height);
b.putClientProperty(PROPERTY_NEGATIVE_INSETS, negativeInsets);
return negativeInsets;
}
return null;
}
/** Restore this component back to its original goodness. */
private void restoreState(JComponent c) {
if (c instanceof AbstractButton) {
AbstractButton b = (AbstractButton) c;
if (b.getClientProperty(WAS_SELECTED) != null) {
b.setSelected(((Boolean) b.getClientProperty(WAS_SELECTED))
.booleanValue());
b.putClientProperty(WAS_SELECTED, null);
}
if (b.getClientProperty(WAS_FOCUS_PAINTED) != null) {
b.setFocusPainted(((Boolean) b
.getClientProperty(WAS_FOCUS_PAINTED)).booleanValue());
b.putClientProperty(WAS_FOCUS_PAINTED, null);
}
}
if (c.getClientProperty(WAS_ENABLED) != null) {
c.setEnabled(((Boolean) c.getClientProperty(WAS_ENABLED))
.booleanValue());
c.putClientProperty(WAS_ENABLED, null);
}
if (c.getClientProperty(WAS_VISIBLE) != null) {
c.setVisible(((Boolean) c.getClientProperty(WAS_VISIBLE))
.booleanValue());
c.putClientProperty(WAS_VISIBLE, null);
}
for (int a = 0; a < c.getComponentCount(); a++) {
if (c.getComponent(a) instanceof JComponent) {
restoreState((JComponent) c.getComponent(a));
}
}
}
public static void removeButtonDecorations(AbstractButton button)
{
button.setBorderPainted(false);
button.setContentAreaFilled(false);
button.setFocusPainted(false);
button.setMargin(new Insets(0, 0, 0, 0));
button.setOpaque(false);
}
private AbstractButton getImageButton( AbstractButton button, String iconPrefix, String iconSuffix ){
button.setHorizontalTextPosition(JButton.CENTER);
button.setVerticalTextPosition(JButton.CENTER);
button.setBorderPainted( false );
button.setContentAreaFilled( false );
button.setFocusPainted( false );
button.setMargin( new Insets(0,0,0,0) );
button.setIcon( TGResourceUtils.loadIcon( iconPrefix + iconSuffix ) );
button.setPressedIcon( TGResourceUtils.loadIcon( iconPrefix + "_pressed" + iconSuffix ) );
button.setRolloverIcon( TGResourceUtils.loadIcon( iconPrefix + "_over" + iconSuffix ) );
button.setSelectedIcon( TGResourceUtils.loadIcon( iconPrefix + "_selected" + iconSuffix ) );
button.setRolloverSelectedIcon( TGResourceUtils.loadIcon( iconPrefix + "_selected_over" + iconSuffix ) );
return button;
}
private AdjustableViewScrollPane createScrollPane() {
AbstractButton zoomAllButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/ZoomAll13.gif"),
false);
zoomAllButton.setFocusable(false);
zoomAllButton.setFocusPainted(false);
zoomAllButton.addActionListener(e -> getLayerCanvas().zoomAll());
AdjustableViewScrollPane scrollPane = new AdjustableViewScrollPane(layerCanvas);
// todo - use sceneImage.getConfiguration() (nf, 18.09.2008)
scrollPane.setBackground(DEFAULT_IMAGE_BACKGROUND_COLOR);
scrollPane.setCornerComponent(zoomAllButton);
return scrollPane;
}