📄 folderbar.java
字号:
/* HEADER*/
package com.sshtools.ui.swing;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
* Simple Swing component that just shows an icon and some boldened text on a darkened
* background. The icon and text can also be derived from an Action.
*
* @author $Author: brett $
* @version $Revision: 1.3 $
*/
public class FolderBar
extends JPanel {
// Private instance variables
private JLabel textLabel;
private JLabel iconLabel;
private Action action;
/**
* Construct a new FolderBar.
*/
public FolderBar() {
this(null, null);
}
/**
* Construct a new FolderBar with some text.
*
* @param text text
*/
public FolderBar(String text) {
this(text, null);
}
/**
* Construct a new FolderBar with some text and an icon.
*
* @param text text
* @param icon icon
*/
public FolderBar(String text, Icon icon) {
super(new BorderLayout());
setOpaque(true);
setBackground(getBackground().darker());
add(textLabel = new JLabel(), BorderLayout.CENTER);
add(iconLabel = new JLabel(), BorderLayout.WEST);
iconLabel.setFont(iconLabel.getFont().deriveFont(Font.BOLD));
textLabel.setVerticalAlignment(JLabel.CENTER);
textLabel.setVerticalTextPosition(JLabel.BOTTOM);
textLabel.setForeground(Color.lightGray);
iconLabel.setVerticalAlignment(JLabel.CENTER);
setIcon(icon);
setText(text);
}
/**
* Get the action that built this folder bar.
*
* @return action
*/
public Action getAction() {
return action;
}
/**
* Set the icon and text from an action. The {@link Action.NAME} values is
* used to derive the text and {@link Action.ICON} for the icon.
*
* @param action
*/
public void setAction(Action action) {
this.action = action;
setIcon(action == null ? null : (Icon) action.getValue(Action.SMALL_ICON));
setText(action == null ? null : (String) action.getValue(Action.LONG_DESCRIPTION));
}
/**
* Set the text of this folder bar.
*
* @param text text
*/
public void setText(String text) {
textLabel.setText(text);
}
/**
* Set the icon on this folder bar.
*
* @param icon icon
*/
public void setIcon(Icon icon) {
iconLabel.setIcon(icon);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -