下面列出了怎么用javax.swing.JSeparator的API类实例代码及写法,或者点击链接到github查看源代码。
private static void appendMenuItem(Component menuItem, StringBuilder builder, String indent) {
if (menuItem instanceof JMenuBar) {
appendMenuSubElements((MenuElement)menuItem, builder, indent);
} else if (menuItem instanceof JPopupMenu) {
appendMenuSubElements((MenuElement)menuItem, builder, indent);
} else if (menuItem instanceof JMenuItem) {
builder.append(NEWLINE);
builder.append(indent);
builder.append(((JMenuItem)menuItem).getText());
builder.append(((JMenuItem)menuItem).isEnabled() ? "" : "[Disabled]");
appendMenuSubElements((JMenuItem)menuItem, builder, "| " + indent);
} else if (menuItem instanceof JSeparator) {
builder.append(NEWLINE);
builder.append(indent);
builder.append("--------");
}
}
public JScrollPane get() {
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
panel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
panel.add(initSelectParserPane());
panel.add(new JSeparator(JSeparator.HORIZONTAL));
panel.add(initParserSettingsPanel());
panel.add(new JSeparator(JSeparator.HORIZONTAL));
panel.add(initPhraseQuerySettingsPanel());
panel.add(new JSeparator(JSeparator.HORIZONTAL));
panel.add(initFuzzyQuerySettingsPanel());
panel.add(new JSeparator(JSeparator.HORIZONTAL));
panel.add(initDateRangeQuerySettingsPanel());
panel.add(new JSeparator(JSeparator.HORIZONTAL));
panel.add(initPointRangeQuerySettingsPanel());
JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.setOpaque(false);
scrollPane.getViewport().setOpaque(false);
return scrollPane;
}
@Override
public void paint( Graphics g, JComponent c ) {
Graphics2D g2 = (Graphics2D) g.create();
try {
FlatUIUtils.setRenderingHints( g2 );
g2.setColor( c.getForeground() );
float width = scale( (float) stripeWidth );
float indent = scale( (float) stripeIndent );
if( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL )
g2.fill( new Rectangle2D.Float( indent, 0, width, c.getHeight() ) );
else
g2.fill( new Rectangle2D.Float( 0, indent, c.getWidth(), width ) );
} finally {
g2.dispose();
}
}
public JFrameMasterCtrlMenuRecents(JMenu jMenuRecents, JMenuItem jMenuItemClear, JMenuItem jMenuItemEmpty, JSeparator jSeparator, ActionListener jMenuItemActionPerformed) {
_jMenuRecents = jMenuRecents;
_jMenuItemClear = jMenuItemClear;
_jMenuItemActionPerformed = jMenuItemActionPerformed;
_jMenuItemEmpty = jMenuItemEmpty;
_jSeparator = jSeparator;
_jMenuItemClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
clearRecents();
updateRecents();
}
});
readRecentsFromFile();
updateRecents();
}
/**
* Adds a new horizontal separator to the keybinds list. The JSeparator spans 2 columns.
*
* @param panel Panel to add the separator to.
*/
private void addKeybindCategorySeparator(JPanel panel) {
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(0, 0, 0, 0);
gbc.gridx = 0;
gbc.gridy = keybindButtonGridYCounter++;
keybindLabelGridYCounter++;
gbc.gridwidth = 2;
panel.add(Box.createVerticalStrut(7), gbc);
JSeparator jsep = new JSeparator(SwingConstants.HORIZONTAL);
panel.add(jsep, gbc);
panel.add(Box.createVerticalStrut(7), gbc);
}
@Override
protected Component createContents() {
JPanel panel = new JPanel(new VerticalLayout());
panel.add(new HyperLink(Actions.build("Pair Another Device", () -> submit(Action.PAIR_ANOTHER))).getComponent());
int remainingDevices = ((Collection<?>) input.getPairingSubsystem().get(PairingSubsystem.ATTR_PAIRINGDEVICES)).size();
if(remainingDevices > 0) {
panel.add(new HyperLink(Actions.build(String.format("Customize %d Remaining Devices", remainingDevices), () -> submit(Action.CUSTOMIZE_ANOTHER))).getComponent());
}
panel.add(new JSeparator(JSeparator.HORIZONTAL));
JButton dismissAll = new JButton(Actions.build("Dismiss All", () -> submit(Action.DISMISS_ALL)));
JPanel buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
buttons.add(Box.createGlue());
buttons.add(dismissAll);
panel.add(buttons);
return panel;
}
private void setControls() {
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
cboFonts.setModel(model);
String[] tags = {"@CURRENTDATE", "@CURRENTTIME", "@STARTTIME", "@RECORDINGTIME", "@UPDATE 60 [email protected]", "@UPDATE 5 [email protected]", "@ONCHANGEONLY", "@ONELINER", "@SCROLLVERTICAL", "@SCROLLHORIZONTAL", "@TYPEWRITER", "", "file:///path/to/file.txt"};
for (String t : tags) {
if (t.length() > 0) {
JMenuItem m = new JMenuItem(t);
m.setActionCommand(t);
m.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
txtText.insert(e.getActionCommand(), txtText.getCaretPosition());
mTextViewer.setText(txtText.getText());
mText.setText(txtText.getText());
}
});
mnuTags.add(m);
} else {
mnuTags.add(new JSeparator());
}
}
}
/**
* Creates a indicator for activation of beta features.
*/
BetaFeaturesIndicator() {
separator = new JSeparator(JSeparator.VERTICAL);
modeLabel = new ResourceLabel("setting.activated_beta_features");
modeLabel.setFont(modeLabel.getFont().deriveFont(Font.BOLD));
modeLabel.setForeground(ICON_COLOR);
modeLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
showBetaBubble();
}
});
ParameterService.registerParameterChangeListener(betaFeaturesListener);
if (Boolean.parseBoolean(ParameterService.getParameterValue(RapidMiner.PROPERTY_RAPIDMINER_UPDATE_BETA_FEATURES))) {
modeLabel.setVisible(true);
separator.setVisible(true);
} else {
modeLabel.setVisible(false);
separator.setVisible(false);
}
}
/**
* The constructor that will add the items to this panel.
*
* @param freeColClient The {@code FreeColClient} for the game.
*/
public ReportIndianPanel(FreeColClient freeColClient) {
super(freeColClient, "reportIndianAction");
Player player = getMyPlayer();
reportPanel.setLayout(new MigLayout("wrap 6, fillx, insets 0",
"[]20px[center]", "[top]"));
boolean needsSeperator = false;
for (Player opponent : CollectionUtils.transform(getGame().getLiveNativePlayers(),
p -> player.hasContacted(p))) {
if (needsSeperator) {
reportPanel.add(new JSeparator(JSeparator.HORIZONTAL),
"newline 20, span, growx, wrap 20");
}
buildIndianAdvisorPanel(player, opponent);
needsSeperator = true;
}
scrollPane.getViewport().setOpaque(false);
reportPanel.setOpaque(true);
reportPanel.doLayout();
}
private void changeModel() {
DefaultComboBoxModel model = (DefaultComboBoxModel)fileMRU.getModel();
model.removeAllElements();
if (isShowWelcome()) {
model.addElement(new StringComboListElement(getWelcomeText(), true));
}
model.addElement(new ComboListElement(getNoneText()) {
public void onSelection() {
validSelection = false;
}
});
JSeparator separ = new JSeparator();
model.addElement(separ);
model.addElement(new ComboListElement(getActionText()) {
public void onSelection() {
validSelection = false;
browseFiles();
}
});
}
public JScrollPane get() {
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
panel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
panel.add(initAnalyzerNamePanel());
panel.add(new JSeparator(JSeparator.HORIZONTAL));
panel.add(initAnalysisChainPanel());
tokenizerTF.setEditable(false);
JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.setOpaque(false);
scrollPane.getViewport().setOpaque(false);
return scrollPane;
}
static void checkSeparators(Component[] menuones, JPopupMenu parent) {
boolean wasSeparator = false;
for (int i = 0; i < menuones.length; i++) {
Component curItem = menuones[i];
if (curItem != null) {
boolean isSeparator = curItem instanceof JSeparator;
if (isSeparator) {
boolean isVisible = curItem.isVisible();
if (isVisible != !wasSeparator) {
//MACOSX whenever a property like enablement or visible is changed, need to remove and add.
// could be possibly split to work differetly on other platform..
parent.remove(i);
JSeparator newOne = createSeparator();
newOne.setVisible(!wasSeparator);
parent.add(newOne, i);
}
}
if (!(curItem instanceof InvisibleMenuItem)) {
wasSeparator = isSeparator;
}
}
}
}
protected void fireItemStateChanged(ItemEvent e) {
switch (e.getStateChange()) {
case ItemEvent.SELECTED:
if (e.getItem() instanceof JSeparator) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
selectNextItem();
}
});
}
break;
case ItemEvent.DESELECTED:
if (!(e.getItem() instanceof JSeparator)) {
lastSelectedIndex = model.getIndexOf(e.getItem());
}
break;
}
super.fireItemStateChanged(e);
}
public SeparatorTitled(String title, boolean bold) {
super(BoxLayout.LINE_AXIS);
JLabel titleLabel = new JLabel(title);
if (bold)
FormUtils.setBold(titleLabel);
titleLabel.setAlignmentY(Component.BOTTOM_ALIGNMENT);
this.add(titleLabel);
this.add(Box.createHorizontalStrut(5));
JSeparator separator = new JSeparator();
separator.setAlignmentY(Container.TOP_ALIGNMENT);
this.add(separator);
this.setMaximumSize(new Dimension(Short.MAX_VALUE, 20));
}
@Override
protected void installDefaults( JSeparator s ) {
super.installDefaults( s );
if( !defaults_initialized ) {
String prefix = getPropertyPrefix();
height = UIManager.getInt( prefix + ".height" );
stripeWidth = UIManager.getInt( prefix + ".stripeWidth" );
stripeIndent = UIManager.getInt( prefix + ".stripeIndent" );
defaults_initialized = true;
}
}
@Override
public Dimension getPreferredSize( JComponent c ) {
if( ((JSeparator) c).getOrientation() == JSeparator.VERTICAL )
return new Dimension( scale( height ), 0 );
else
return new Dimension( 0, scale( height ) );
}
public void addSeparator(int gridx, int gridy, int width) {
JSeparator sep = new JSeparator(JSeparator.HORIZONTAL);
sep.setPreferredSize(new Dimension(2, 1));
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = gridx;
gbc.gridy = gridy;
gbc.gridwidth = width;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1;
add(sep, gbc);
}
private JPanel content() {
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
panel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
panel.add(controller());
panel.add(new JSeparator(JSeparator.HORIZONTAL));
panel.add(logs());
return panel;
}
private void updateRecents() {
this.jMenuRecents.removeAll();
if (this.recents.isEmpty()) {
this.jMenuRecents.add(this.jMenuItemEmpty);
}
else {
for (String path : this.recents) {
javax.swing.JMenuItem jMenuItem = new javax.swing.JMenuItem();
jMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemRecentsItemActionPerformed(evt);
}
});
jMenuItem.setText(path);
jMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/text-x-generic.png")));
this.jMenuRecents.add(jMenuItem);
}
}
this.jMenuRecents.add(new javax.swing.JSeparator());
this.jMenuRecents.add(this.jMenuRecentsClear);
this.jMenuRecents.revalidate();
this.dumpRecentsToFile();
}
private void installCustomizations(QOptionPane optionPane) {
JLabel iconLabel = getIconLabel(optionPane);
JTextArea mainText = getMainMessageTextArea(optionPane);
JTextArea secondaryText = getSecondaryMessageTextArea(optionPane);
JPanel footerContainer = getFooterContainer(optionPane);
JSeparator footerSeparator = getFooterSeparator(optionPane);
JPanel upperBody = getUpperBody(optionPane);
installBorder(footerContainer,
getInsets(optionPane, KEY_FOOTER_INSETS), new Color(0xffDDDDDD));
installBorder(upperBody, getInsets(optionPane, KEY_UPPER_BODY_INSETS),
new Color(0xDDffDD));
installBorder(iconLabel, getInsets(optionPane, KEY_ICON_INSETS),
new Color(0xffDDff));
installBorder(mainText, getInsets(optionPane, KEY_MAIN_MESSAGE_INSETS),
new Color(0xDDDDff));
installBorder(secondaryText,
getInsets(optionPane, KEY_SECONDARY_MESSAGE_INSETS), new Color(
0xDDffff));
Color separatorColor = getColor(optionPane, KEY_FOOTER_SEPARATOR_COLOR);
footerSeparator.setVisible(separatorColor != null);
footerSeparator.setUI(new LineSeparatorUI(separatorColor));
mainText.setFont(getFont(optionPane, KEY_MAIN_MESSAGE_FONT));
secondaryText.setFont(getFont(optionPane, KEY_SECONDARY_MESSAGE_FONT));
mainText.setForeground(getColor(optionPane, KEY_MAIN_MESSAGE_COLOR));
secondaryText.setForeground(getColor(optionPane,
KEY_SECONDARY_MESSAGE_COLOR));
mainText.setDisabledTextColor(getColor(optionPane,
KEY_MAIN_MESSAGE_COLOR));
secondaryText.setDisabledTextColor(getColor(optionPane,
KEY_SECONDARY_MESSAGE_COLOR));
updateMainMessage(optionPane);
updateSecondaryMessage(optionPane);
updateFooter(optionPane);
}
private void addSeparator(JPanel panel, String label) {
JPanel innerPanel = new JPanel(new GridBagLayout());
innerPanel.add(new JLabel(label),
new GridBagConstraints(0, 0,
1, 1,
0.0, 0.0,
GridBagConstraints.LINE_START,
GridBagConstraints.NONE,
new Insets(0, 0, 0, 0),
0, 0));
innerPanel.add(new JSeparator(),
new GridBagConstraints(1, 0,
1, 1,
0.9, 0.0,
GridBagConstraints.LINE_START,
GridBagConstraints.HORIZONTAL,
new Insets(0, 6, 0, 6),
0, 0));
panel.add(innerPanel,
new GridBagConstraints(0, linesCount++,
2, 1,
1.0, 0.0,
GridBagConstraints.LINE_START,
GridBagConstraints.HORIZONTAL,
new Insets(6, 6, 6, 0),
0, 0));
}
/**
* @see javax.swing.plaf.ComponentUI#update(java.awt.Graphics, javax.swing.JComponent)
*/
public void update(Graphics g, JComponent c) {
SeaGlassContext context = getContext(c);
JSeparator separator = (JSeparator) context.getComponent();
SeaGlassLookAndFeel.update(context, g);
context.getPainter().paintSeparatorBackground(context,
g, 0, 0, c.getWidth(), c.getHeight(),
separator.getOrientation());
paint(context, g);
context.dispose();
}
/**
* The separator will be inserted only if it is really necessary.
*/
@Override
public void addSeparator ()
{
int count = getComponentCount();
if ((count > 0) && !(getComponent(count - 1) instanceof JSeparator)) {
super.addSeparator();
}
}
public AstrosoftToolBar(Color mclr, AstrosoftActionManager actionMgr) {
buttons = new ArrayList<JButton>();
for(Command toolBarItem : Command.toolBarItems()){
buttons.add(new JButton(actionMgr.getAction(toolBarItem)));
}
for (JButton b:buttons){
add(b);
String cmd = b.getActionCommand();
if (cmd.equals(Command.PRINT) || cmd.equals(Command.SHADBALA_VIEW) || cmd.equals(Command.PANCHANG_VIEW)){
//addSeparator();
JSeparator separator = new JSeparator(SwingConstants.VERTICAL);
// FIXME size of separator
//separator.setPreferredSize(new Dimension(1,20));
/*separator.setSize(new Dimension(100,100));
separator.setMaximumSize(new Dimension(100,100));
separator.setMinimumSize(new Dimension(100,100));
separator.setVisible(true);
separator.setBounds(0,0,20,20);*/
add(separator);
}
b.setText("");
}
}
@Override
public void startup() {
WindowListener exitListener = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
Window window = e.getWindow();
window.setVisible(false);
window.dispose();
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {
} finally {
System.exit(0);
}
}
};
addWindowListener(exitListener);
setIconImage(Icons.getIcon(Icons.OPT4J).getImage());
setTitle(title);
setLayout(new BorderLayout());
JSeparator jSeparator = new JSeparator();
JPanel toolBarPanel = new JPanel(new BorderLayout());
toolBarPanel.add(toolBar, BorderLayout.CENTER);
toolBarPanel.add(jSeparator, BorderLayout.SOUTH);
add(toolBarPanel, BorderLayout.NORTH);
add(contentPanel, BorderLayout.CENTER);
setJMenuBar(menu);
menu.startup();
toolBar.startup();
contentPanel.startup();
pack();
setVisible(true);
}
@Override
protected void createMenu(final JComponent menu) {
if (m_containerNode == null) {
m_containerNode =
getModuleContainerNode(CNodeExpander.findNode(getProjectTree(), m_database));
}
menu.add(new JMenuItem(CActionProxy.proxy(new CImportModuleAction(getParent(), m_database))));
menu.add(new JMenuItem(CActionProxy
.proxy(new CRefreshRawModulesAction(getParent(), m_database))));
menu.add(new JMenuItem(CActionProxy.proxy(new CResolveAllFunctionsAction(menu, m_database))));
menu.add(new JSeparator());
final JMenu sortMenu = new JMenu("Sort");
final JRadioButtonMenuItem idMenu =
new JRadioButtonMenuItem(new CActionSortModulesById(m_containerNode));
idMenu.setSelected(!m_containerNode.isSorted());
sortMenu.add(idMenu);
final JRadioButtonMenuItem nameMenu =
new JRadioButtonMenuItem(new CActionSortModulesByName(m_containerNode));
nameMenu.setSelected(m_containerNode.isSorted());
sortMenu.add(nameMenu);
menu.add(sortMenu);
}
/**
* Remove any potential orphan separator at the end of the tool bar
*/
public static void purgeSeparator (JToolBar toolBar)
{
int count = toolBar.getComponentCount();
if (toolBar.getComponent(count - 1) instanceof JSeparator) {
toolBar.remove(count - 1);
}
}
private int getRowCount(Component component, int count) {
Component[] items = ((JMenu) component).getMenuComponents();
if (items == null) {
return 0;
}
for (int i = 0; i < items.length; i++) {
if (items[i] instanceof JMenu) {
count = getRowCount(items[i], count);
}
if (!(items[i] instanceof JSeparator)) {
count++;
}
}
return count;
}
private JPanel content() {
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
panel.add(basicSettings());
panel.add(new JSeparator(JSeparator.HORIZONTAL));
panel.add(expertSettings());
panel.add(new JSeparator(JSeparator.HORIZONTAL));
panel.add(buttons());
return panel;
}
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
if (value instanceof Provider) {
Provider provider = (Provider)value;
String text = provider.getDisplayName();
if (value.equals(defaultProvider) && (!(value instanceof DefaultProvider))) {
text += NbBundle.getMessage(PersistenceProviderComboboxHelper.class, "LBL_DEFAULT_PROVIDER");
}
setText(text);
} else if (SEPARATOR.equals(value)) {
JSeparator s = new JSeparator();
s.setPreferredSize(new Dimension(s.getWidth(), 1));
s.setForeground(Color.BLACK);
return s;
} else if (EMPTY.equals(value)) {
setText(" ");
} else if (value instanceof LibraryItem) {
setText(((LibraryItem) value).getText());
} else {
setText(value != null ? value.toString() : ""); // NOI18N
}
return this;
}