下面列出了javax.swing.JButton#isVisible ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void updateVisibility() {
// hide button panel when no button is visible
boolean visible = false;
for (Component component : getComponents()) {
if (component instanceof JButton) {
JButton button = (JButton) component;
if (button.isVisible()) {
visible = true;
}
}
}
setVisible(visible);
}
private void init(String message, OnlyMessageBox.MessageType messageType, int option) {
iconMap = new HashMap<OnlyMessageBox.MessageType, Icon>();
iconMap.put(OnlyMessageBox.MessageType.ERROR, new ImageIcon());
iconMap.put(OnlyMessageBox.MessageType.INFORMATION, new ImageIcon());
iconMap.put(OnlyMessageBox.MessageType.QUESTION, new ImageIcon());
iconMap.put(OnlyMessageBox.MessageType.WARNING, new ImageIcon());
JPanel buttonPane = new JPanel();
lbMessage = new JLabel(message, iconMap.get(messageType), JLabel.LEFT);
btnOK = new JButton("确定");
btnCancel = new JButton("取消");
btnYes = new JButton("是");
btnNo = new JButton("否");
JButton[] buttons = {btnOK, btnYes, btnNo, btnCancel};
int[] options = {OK_OPTION, YES_OPTION, NO_OPTION, CANCEL_OPTION};
final Dimension buttonSize = new Dimension(69, 21);
int index = 0;
boolean hasDefaultButton = false;
lbMessage.setIconTextGap(16);
lbMessage.setHorizontalAlignment(JLabel.LEFT);
lbMessage.setVerticalAlignment(JLabel.TOP);
lbMessage.setVerticalTextPosition(JLabel.TOP);
lbMessage.setBorder(new EmptyBorder(15, 25, 15, 25));
buttonPane.setLayout(new LineLayout(6, 0, 0, 0, 0, LineLayout.LEADING, LineLayout.LEADING, LineLayout.HORIZONTAL));
buttonPane.setPreferredSize(new Dimension(-1, 33));
buttonPane.setBorder(new EmptyBorder(5, 9, 0, 9));
buttonPane.setBackground(new Color(255, 255, 255, 170));
for (JButton button : buttons) {
button.setActionCommand(String.valueOf(options[index]));
button.setPreferredSize(buttonSize);
button.setVisible((option & options[index]) != 0);
button.addActionListener(this);
buttonPane.add(button, LineLayout.END);
index++;
if (!hasDefaultButton && button.isVisible()) {
getRootPane().setDefaultButton(button);
hasDefaultButton = true;
}
}
getContentPane().setLayout(new LineLayout(0, 1, 1, 3, 1, LineLayout.LEADING, LineLayout.LEADING, LineLayout.VERTICAL));
getContentPane().add(lbMessage, LineLayout.MIDDLE_FILL);
getContentPane().add(buttonPane, LineLayout.END_FILL);
}
protected LayoutBlueprint(boolean initialPermitLocked) {
super(ANIMATION_DURATION, 1F);
this.initialPermitLocked = initialPermitLocked;
Insets insets = getInsets();
int height = getHeight() - insets.top - insets.bottom;
int remainingHeight = height;
float totalVerticalWeight = 0;
Map<JComponent, Number> verticalWeightMap = new HashMap<JComponent, Number>();
for (int a = 0; a < sections.size(); a++) {
Section section = sections.get(a);
JPanel body = section.getBody();
JButton header = getHeader(section);
Boolean collapsed = (Boolean) header
.getClientProperty(COLLAPSED);
if (collapsed == null)
collapsed = Boolean.FALSE;
if (!header.isVisible())
collapsed = true;
components.add(header);
components.add(body);
if (header.isVisible())
visibleComponents.add(header);
if ((!collapsed))
visibleComponents.add(body);
Number n = (Number) section.getProperty(VERTICAL_WEIGHT);
if (n == null)
n = 0;
if (visibleComponents.contains(body)) {
totalVerticalWeight += n.floatValue();
if (n.floatValue() != 0)
verticalWeightMap.put(body, n);
}
if (visibleComponents.contains(header)) {
Dimension headerSize = header.getPreferredSize();
heightMap.put(header, headerSize.height);
remainingHeight -= headerSize.height;
} else {
heightMap.put(header, 0);
}
originalHeightMap.put(header, header.getHeight());
if (visibleComponents.contains(body) && n.floatValue() == 0) {
Dimension bodySize = body.getPreferredSize();
heightMap.put(body, bodySize.height);
remainingHeight -= bodySize.height;
} else {
heightMap.put(body, 0);
}
originalHeightMap.put(body, body.getHeight());
}
if (remainingHeight > 0 && totalVerticalWeight > 0) {
// divide the remaining height based on the vertical weight
int designatedHeight = 0;
JComponent lastC = null;
for (JComponent jc : verticalWeightMap.keySet()) {
Number weight = verticalWeightMap.get(jc);
int i = (int) (weight.floatValue() / totalVerticalWeight * remainingHeight);
heightMap.put(jc, heightMap.get(jc) + i);
designatedHeight += i;
lastC = jc;
}
// due to rounding error, we may have a few extra pixels:
int remainingPixels = remainingHeight - designatedHeight;
// tack them on to someone. anyone.
heightMap.put(lastC, heightMap.get(lastC) + remainingPixels);
}
}