下面列出了怎么用javax.swing.BorderFactory的API类实例代码及写法,或者点击链接到github查看源代码。
private void initComponents(final ApplicationOverviewModel model) {
setLayout(new BorderLayout());
setOpaque(false);
final HTMLTextArea area = new HTMLTextArea("<nobr>" + getGeneralProperties(model) + "</nobr>"); // NOI18N
area.setBorder(BorderFactory.createEmptyBorder(14, 8, 14, 8));
DataSource source = model.getSource();
if (source instanceof Application) {
oomeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (Jvm.PROPERTY_DUMP_OOME_ENABLED.equals(evt.getPropertyName())) {
int selStart = area.getSelectionStart();
int selEnd = area.getSelectionEnd();
area.setText("<nobr>" + getGeneralProperties(model) + "</nobr>"); // NOI18N
area.select(selStart, selEnd);
}
}
};
Jvm jvm = JvmFactory.getJVMFor((Application)source);
jvm.addPropertyChangeListener(WeakListeners.propertyChange(oomeListener,jvm));
}
add(area, BorderLayout.CENTER);
}
private void addAction (Action action) {
String name = (String) action.getValue(Action.NAME);
LinkButton btn = new LinkButton(name);
btn.addActionListener(action);
if (notEmpty) {
JLabel separator = new javax.swing.JLabel();
separator.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(2, 0, 2, 0),
BorderFactory.createLineBorder(Color.BLACK, 1)
));
horizontalSeqGroup
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(separator)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED);
verticalParallelGroup
.addComponent(separator, GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
}
horizontalSeqGroup
.addComponent(btn, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE);
verticalParallelGroup
.addComponent(btn, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE);
notEmpty = true;
}
/**
* Create Component(JPanel) and add separator and JLabel to it.
*
* @param cell JLabel
* @return panel
*/
private Component panelWithSeparator(JLabel cell) {
// create separator
JSeparator separator = new JSeparator(SwingConstants.VERTICAL) {
private static final long serialVersionUID = -6385848933295984637L;
@Override
public Dimension getPreferredSize() {
return new Dimension(3, 3);
}
};
separator.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
// create panel
JPanel panel = new JPanel(new BorderLayout());
panel.add(separator, BorderLayout.WEST);
panel.add(cell, BorderLayout.EAST);
panel.add(versionLabel, BorderLayout.CENTER);
return panel;
}
private JPanel createPlotPanel() {
JPanel plotPanel = new JPanel(new LCBLayout(3));
plotPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
plotPanel.add(new JLabel(localizationResources.getString(
"AngleOffset")));
this.angleOffset = new JTextField(Double.toString(
this.angleOffsetValue));
this.angleOffset.setActionCommand("AngleOffsetValue");
this.angleOffset.addActionListener(this);
this.angleOffset.addFocusListener(this);
plotPanel.add(this.angleOffset);
plotPanel.add(new JPanel());
plotPanel.add(new JLabel(localizationResources.getString(
"Manual_TickUnit_value")));
this.manualTickUnit = new JTextField(Double.toString(
this.manualTickUnitValue));
this.manualTickUnit.setActionCommand("TickUnitValue");
this.manualTickUnit.addActionListener(this);
this.manualTickUnit.addFocusListener(this);
plotPanel.add(this.manualTickUnit);
plotPanel.add(new JPanel());
return plotPanel;
}
HorizontalScroller(JComponent view) {
super(view, VERTICAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_AS_NEEDED);
setBorder(BorderFactory.createEmptyBorder());
setViewportBorder(BorderFactory.createEmptyBorder());
getViewport().setOpaque(false);
setOpaque(false);
super.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getModifiers() == MouseWheelEvent.SHIFT_MASK) {
scroll(getHorizontalScrollBar(), e);
} else {
getParent().dispatchEvent(e);
}
}
});
}
public ThreadDumpWindow(ThreadDump td) {
setLayout(new BorderLayout());
setFocusable(true);
setRequestFocusEnabled(true);
setName(Bundle.ThreadDumpWindow_Caption(StringUtils.formatUserDate(td.getTime())));
setIcon(Icons.getImage(ProfilerIcons.THREAD));
StringBuilder text = new StringBuilder();
printThreads(text, td);
a = new HTMLTextArea() {
protected void showURL(URL url) {
if (url == null) {
return;
}
String urls = url.toString();
ThreadDumpWindow.this.showURL(urls);
}
};
a.setEditorKit(new CustomHtmlEditorKit());
a.setText(text.toString());
a.setCaretPosition(0);
JScrollPane sp = new JScrollPane(a);
sp.setBorder(BorderFactory.createEmptyBorder());
sp.setViewportBorder(BorderFactory.createEmptyBorder());
add(sp, BorderLayout.CENTER);
}
/**
* Creates a new N9Component object.
*
* @param text the text
* @param n9 the n9
* @param is the is
* @param foregroundColor the foreground color
* @param f the f
* @return the j label
*/
public static JLabel createLabel_root(String text
, final NinePatch n9, Insets is
, Color foregroundColor, Font f)
{
JLabel l = new JLabel(text){
public void paintComponent(Graphics g) {
n9.draw((Graphics2D)g, 0, 0, this.getWidth(), this.getHeight());
super.paintComponent(g);
}
};
if(is != null)
l.setBorder(BorderFactory.createEmptyBorder(is.top, is.left, is.bottom, is.right));
if(foregroundColor != null)
l.setForeground(foregroundColor);
if(f != null)
l.setFont(f);
return l;
}
public JPanel get() {
JPanel panel = new JPanel(new BorderLayout());
panel.setOpaque(false);
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JPanel header = new JPanel(new FlowLayout(FlowLayout.LEADING));
header.setOpaque(false);
header.add(new JLabel(MessageUtils.getLocalizedMessage("logs.label.see_also")));
JLabel logPathLabel = new JLabel(LukeMain.LOG_FILE);
header.add(logPathLabel);
panel.add(header, BorderLayout.PAGE_START);
panel.add(new JScrollPane(logTextArea), BorderLayout.CENTER);
return panel;
}
private JPanel createGlobalScriptTab() {
final JPanel globalHeader2 = new JPanel( new BorderLayout() );
globalHeader2.add( new JLabel( Messages.getString( "QueryEditorPanel.GlobalScript" ) ), BorderLayout.CENTER );
globalHeader2.add( new JButton( globalTemplateAction ), BorderLayout.EAST );
final JPanel globalScriptHeader = new JPanel( new VerticalLayout( 5, VerticalLayout.BOTH, VerticalLayout.TOP ) );
globalScriptHeader.add( new JLabel( Messages.getString( "QueryEditorPanel.GlobalScriptLanguage" ) ) );
globalScriptHeader.add( globalLanguageField );
globalScriptHeader.add( globalHeader2 );
final JPanel globalScriptContentHolder = new JPanel( new BorderLayout() );
globalScriptContentHolder.add( globalScriptHeader, BorderLayout.NORTH );
globalScriptContentHolder.add( new RTextScrollPane( 700, 600, globalScriptTextArea, true ), BorderLayout.CENTER );
globalScriptContentHolder.setBorder( BorderFactory.createEmptyBorder( 8, 8, 8, 8 ) );
return globalScriptContentHolder;
}
public TranscriptAlert() {
setLayout(new GridBagLayout());
setBackground(new Color(250, 249, 242));
add(imageLabel, new GridBagConstraints(0, 0, 1, 3, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
add(titleLabel, new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
titleLabel.setFont(new Font("Dialog", Font.BOLD, 11));
titleLabel.setForeground(new Color(211, 174, 102));
add(yesButton, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
add(cancelButton, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
yesButton.setForeground(new Color(73, 113, 196));
cancelButton.setForeground(new Color(73, 113, 196));
cancelButton.setFont(new Font("Dialog", Font.BOLD, 10));
yesButton.setFont(new Font("Dialog", Font.BOLD, 10));
yesButton.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(73, 113, 196)));
cancelButton.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(73, 113, 196)));
cancelButton.setVisible(false);
setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.white));
}
private void createDiffToolLoggingSettings()
{
diffToolLabel = new JLabel("Logging Root Folder: ");
diffToolLabel.setBorder(BorderFactory.createRaisedBevelBorder());
diffToolLabel.setBounds(10, 10, 150, 25);
this.add(diffToolLabel);
diffToolField = new JTextField();
diffToolField.setBounds(170, 10, 200, 25);
this.add(diffToolField);
diffToolLogLevelComboBox = new JComboBox<>();
diffToolLogLevelComboBox.setBounds(390, 10, 100, 25);
diffToolLogLevelComboBox.addItem(Level.ERROR);
diffToolLogLevelComboBox.addItem(Level.WARN);
diffToolLogLevelComboBox.addItem(Level.INFO);
diffToolLogLevelComboBox.addItem(Level.DEBUG);
diffToolLogLevelComboBox.addItem(Level.TRACE);
this.add(diffToolLogLevelComboBox);
}
private JPanel createPubOption() {
JPanel optsPanelCon = new VerticalPanel();
optsPanelCon.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Pub options"));
qosChoice = new JLabeledChoice("QoS Level:", new String[] { String.valueOf(QOS_0), String.valueOf(QOS_1), String.valueOf(QOS_2) }, true, false);
qosChoice.addChangeListener(this);
JPanel optsPanel = new HorizontalPanel();
optsPanel.add(qosChoice);
optsPanel.add(retainedMsg);
optsPanel.add(topicName);
topicName.setToolTipText("Name of topic that the message will be sent to.");
optsPanel.add(timestamp);
optsPanelCon.add(optsPanel);
return optsPanelCon;
}
@Override
Style create() {
// Text
Color highlight = new Color(219, 191, 130);
Color shadow = new Color(36, 14, 0); // Light brown (also inactive text)
PixmapStyle style = new PixmapStyle("data/gui/panel_brick_brown_001.png",
false, highlight, shadow, Color.white, Color.white);
// Border
Color blightin = new Color(181, 140, 50);
Color bshadowin = new Color(98, 47, 15);
style.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,
highlight, blightin, shadow, bshadowin));
style.setBorderDown(BorderFactory.createBevelBorder(BevelBorder.LOWERED,
highlight, blightin, shadow, bshadowin));
return style;
}
ResultPanelTree(ResultDisplayHandler displayHandler, StatisticsPanel statPanel) {
super(new BorderLayout());
treeView = new ResultTreeView();
treeView.getAccessibleContext().setAccessibleName(Bundle.ACSN_TestResults());
treeView.getAccessibleContext().setAccessibleDescription(Bundle.ACSD_TestResults());
treeView.setBorder(BorderFactory.createEtchedBorder());
// resultBar.setPassedPercentage(0.0f);
JToolBar toolBar = new JToolBar();
toolBar.setFloatable(false);
toolBar.add(resultBar);
toolBar.setBorder(BorderFactory.createEtchedBorder());
add(toolBar, BorderLayout.NORTH);
add(treeView, BorderLayout.CENTER);
explorerManager = new ExplorerManager();
explorerManager.setRootContext(rootNode = new RootNode(displayHandler.getSession(), filterMask));
explorerManager.addPropertyChangeListener(this);
initAccessibility();
this.displayHandler = displayHandler;
this.statPanel = statPanel;
displayHandler.setLookup(ExplorerUtils.createLookup(explorerManager, new ActionMap()));
}
/**
* Creates preformatted instance of ScrollableContainer to be used in Options
* dialog. All insets are already initialized to defaults, the client components
* should have zero outer insets.
*
* @param contents component to be displayed
* @return preformatted instance of ScrollableContainer
*/
public static ScrollableContainer createScrollableContainer(JComponent contents) {
ScrollableContainer container = new ScrollableContainer(contents,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
container.setViewportBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
container.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 5));
return container;
}
/**
* Report a standard tool border entity, which is a blank border.
*
* @return the standard tool border
*/
public static Border getToolBorder ()
{
if (toolBorder == null) {
toolBorder = BorderFactory.createEmptyBorder(1, 2, 1, 2);
}
return toolBorder;
}
public void show( JComponent invoker, int x, int y ) {
JPanel panel = new JPanel();
panel.setOpaque( false );
fillContent( panel );
popup = new JPopupMenu();
popup.add( panel );
if( windowsLaF ) {
popup.setBorder( BorderFactory.createLineBorder( windowsSeparatorColor.darker() ));
}
popup.show( invoker, x, y );
}
public void init() {
this.setTitle("管理账户状态");
this.setSize(320, 430);
Point p = WindowUtils.getPointForCentering(this);
this.setLocation(p);
this.setModal(true);
this.statusField.setActionCommand(CMD_STATUS_SELECT);
this.statusField.addActionListener(this);
this.statusField.setSelectedIndex(0);
this.okButton.setActionCommand(ActionName.OK.name());
this.okButton.addActionListener(this);
this.cancelButton.setActionCommand(ActionName.CANCEL.name());
this.cancelButton.addActionListener(this);
this.previewButton.setActionCommand(CMD_PREVIEW);
this.previewButton.addActionListener(this);
JXPanel loginPanel = new JXPanel(new MigLayout("wrap 2, gap 10px", "[45%][55%]"));
loginPanel.add(this.statusLabel, "sg lbl");
loginPanel.add(this.statusField, "sg fd, grow");
loginPanel.add(this.descField, "span, grow");
loginPanel.add(this.previewButton, "gaptop 5px, span, split 3, align center");
loginPanel.setBorder(BorderFactory.createTitledBorder("登陆管理"));
JXPanel panel = new JXPanel(new MigLayout("wrap 1, gap 10px", "[100%]"));
this.setLayout(new MigLayout("wrap 1"));
panel.add(loginPanel);
panel.add(this.okButton, "gaptop 5px, span, split 3, align center");
panel.add(this.cancelButton);
this.add(panel, "width 100%, height 100%");
}
public ColorEditor(String fieldName, Object obj, Field field, int index, Class<?> type) {
this.obj = obj;
this.field = field;
this.index = index;
this.type = type;
this.fieldName = fieldName;
setLayout(new FlowLayout());
buttonChange = new JButton("") {
@Override
protected void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
super.paintBorder(g);
}
};
buttonChange.setToolTipText(AppStrings.translate("button.selectcolor.hint"));
buttonChange.setCursor(new Cursor(Cursor.HAND_CURSOR));
buttonChange.addActionListener(this);
buttonChange.setBorderPainted(true);
buttonChange.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
Dimension colorDim = new Dimension(16, 16);
buttonChange.setSize(colorDim);
buttonChange.setPreferredSize(colorDim);
add(buttonChange);
reset();
}
/**
* Returns a panel that appears at the bottom of the calendar panel -
* contains a button for selecting today's date.
*
* @return the panel.
*/
private JPanel constructControlPanel() {
final JPanel p = new JPanel();
p.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));
this.todayButton = new JButton("Today");
this.todayButton.addActionListener(this);
this.todayButton.setActionCommand("todayButtonClicked");
p.add(this.todayButton);
return p;
}
@Override
public Component add(ProfilerToolbar toolbar, int index) {
JToolBar implToolbar = ((Impl)toolbar).toolbar;
implToolbar.setBorder(BorderFactory.createEmptyBorder());
implToolbar.setOpaque(false);
implToolbar.putClientProperty("Toolbar.noGTKBorder", Boolean.TRUE); // NOI18N
return add(implToolbar, index);
}
public JPanel createAuthentication() {
JPanel optsPanelCon = new VerticalPanel();
optsPanelCon.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "User authentication"));
JPanel optsPanel = new HorizontalPanel();
optsPanel.add(userNameAuth);
optsPanel.add(passwordAuth);
optsPanelCon.add(optsPanel);
return optsPanelCon;
}
public SuccessfulSubmissionDialog(Exercise exercise, SubmissionResult result, Project project) {
logger.info("Creating SuccessfulSubmissionDialog. @SuccessfulSubmissionDialog");
this.setTitle(exercise.getName() + " passed");
JPanel contentPane = new JPanel();
contentPane.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
setContentPane(contentPane);
addYayLabel();
addVSpace(6);
if (exercise.requiresReview() && !result.getMissingReviewPoints().isEmpty()) {
addRequiresReviewLabels();
}
addVSpace(6);
addPointsLabel(result);
addVSpace(10);
addModelSolutionButton(result, project);
addVSpace(20);
addFeedbackQuestions(result); // TODO: maybe put in box
addVSpace(10);
addOkButton();
addNextExerciseButton();
addNextExerciseListener(result, project);
addOkListener(result, project);
setAlwaysOnTop(true);
pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
this.requestFocusInWindow(true);
}
public ButtonTabComponent(final JTabbedPane pane, ArrayList<AreaDeTexto> adts, ArrayList<String> arqsAbertos) {
//unset default FlowLayout' gaps
super(new FlowLayout(FlowLayout.LEFT, 0, 0));
if (pane == null) {
throw new NullPointerException("");
}
this.pane = pane;
this.adts = adts;
this.arquivosAbertos = arqsAbertos;
setOpaque(false);
//make JLabel read titles from JTabbedPane
JLabel label = new JLabel() {
public String getText() {
int i = pane.indexOfTabComponent(ButtonTabComponent.this);
if (i != -1) {
return pane.getTitleAt(i);
}
return null;
}
};
add(label);
//add more space between the label and the button
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
//tab button
JButton button = new TabButton();
add(button);
//add more space to the top of the component
setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
}
private Component wrap(Component c, String title) {
JScrollPane s = new JScrollPane(c);
s.setBackground(Color.white);
s.setMinimumSize(new Dimension(400,15));
s.setPreferredSize(new Dimension(400,200));
s.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(0,5,0,5), title));
return s;
}
/**
* Creates the map pane.
*
* @return the j map pane
*/
private SLDMapPane createMapPane() {
SLDMapPane internalMapPane = new SLDMapPane();
internalMapPane.setBackground(
PrefManager.getInstance().getPrefData().getBackgroundColour());
internalMapPane.setBorder(BorderFactory.createLineBorder(Color.BLACK));
return internalMapPane;
}
protected Border createInstanceImpl() {
Insets i = insets.createInstance();
if (i.top == 0 && i.left == 0 && i.bottom == 0 && i.right == 0) {
return BorderFactory.createEmptyBorder();
} else {
return BorderFactory.createEmptyBorder(i.top, i.left, i.bottom, i.right);
}
}
void setActiveFlag(boolean isActive) {
setFont(isActive ? ON_FONT : OFF_FONT);
setBorder(isActive
? BorderFactory.createMatteBorder(2, 2, 2, 2, MagicStyle.getRolloverColor())
: null
);
}
public void clearScrollBorders() {
if (getComponentCount() > 0) {
Component c = getComponent(0);
if (c instanceof JScrollPane) {
((JScrollPane)c).setBorder(BorderFactory.createEmptyBorder());
((JScrollPane)c).setViewportBorder(BorderFactory.createEmptyBorder());
}
}
}
/**
* No -arguments constructor.
*/
public LegendBuilder() {
legendPanel = new JPanel();
legendPanel.setLayout(new BoxLayout(legendPanel, BoxLayout.Y_AXIS));
border = BorderFactory.createTitledBorder("Legend");
legendPanel.setBorder(border);
}