下面列出了javax.swing.JLabel#setDisplayedMnemonic ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private JPanel createListPanel(final ServiceItemListModel model,
final String title,
final char mnemonic) {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
JList<ServiceItem> list = new JList<>(model);
list.setCellRenderer(new ServiceItemListRenderer());
JLabel label = new JLabel(title);
label.setLabelFor(list);
label.setDisplayedMnemonic(mnemonic);
JPanel labelPanel = new JPanel();
labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.X_AXIS));
labelPanel.add(label, BorderLayout.EAST);
labelPanel.add(Box.createHorizontalGlue());
panel.add(labelPanel);
panel.add(new JScrollPane(list));
return panel;
}
/**
* @noinspection ALL
*/
private void $$$loadLabelText$$$(JLabel component, String text) {
StringBuffer result = new StringBuffer();
boolean haveMnemonic = false;
char mnemonic = '\0';
int mnemonicIndex = -1;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '&') {
i++;
if (i == text.length()) break;
if (!haveMnemonic && text.charAt(i) != '&') {
haveMnemonic = true;
mnemonic = text.charAt(i);
mnemonicIndex = result.length();
}
}
result.append(text.charAt(i));
}
component.setText(result.toString());
if (haveMnemonic) {
component.setDisplayedMnemonic(mnemonic);
component.setDisplayedMnemonicIndex(mnemonicIndex);
}
}
private JPanel createListPanel(final ServiceItemListModel model,
final String title,
final char mnemonic) {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
JList<ServiceItem> list = new JList<>(model);
list.setCellRenderer(new ServiceItemListRenderer());
JLabel label = new JLabel(title);
label.setLabelFor(list);
label.setDisplayedMnemonic(mnemonic);
JPanel labelPanel = new JPanel();
labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.X_AXIS));
labelPanel.add(label, BorderLayout.EAST);
labelPanel.add(Box.createHorizontalGlue());
panel.add(labelPanel);
panel.add(new JScrollPane(list));
return panel;
}
/**
* @noinspection ALL
*/
private void $$$loadLabelText$$$(JLabel component, String text) {
StringBuffer result = new StringBuffer();
boolean haveMnemonic = false;
char mnemonic = '\0';
int mnemonicIndex = -1;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '&') {
i++;
if (i == text.length()) break;
if (!haveMnemonic && text.charAt(i) != '&') {
haveMnemonic = true;
mnemonic = text.charAt(i);
mnemonicIndex = result.length();
}
}
result.append(text.charAt(i));
}
component.setText(result.toString());
if (haveMnemonic) {
component.setDisplayedMnemonic(mnemonic);
component.setDisplayedMnemonicIndex(mnemonicIndex);
}
}
/**
* @noinspection ALL
*/
private void $$$loadLabelText$$$(JLabel component, String text) {
StringBuffer result = new StringBuffer();
boolean haveMnemonic = false;
char mnemonic = '\0';
int mnemonicIndex = -1;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '&') {
i++;
if (i == text.length()) break;
if (!haveMnemonic && text.charAt(i) != '&') {
haveMnemonic = true;
mnemonic = text.charAt(i);
mnemonicIndex = result.length();
}
}
result.append(text.charAt(i));
}
component.setText(result.toString());
if (haveMnemonic) {
component.setDisplayedMnemonic(mnemonic);
component.setDisplayedMnemonicIndex(mnemonicIndex);
}
}
/**
* @noinspection ALL
*/
private void $$$loadLabelText$$$(JLabel component, String text) {
StringBuffer result = new StringBuffer();
boolean haveMnemonic = false;
char mnemonic = '\0';
int mnemonicIndex = -1;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '&') {
i++;
if (i == text.length()) break;
if (!haveMnemonic && text.charAt(i) != '&') {
haveMnemonic = true;
mnemonic = text.charAt(i);
mnemonicIndex = result.length();
}
}
result.append(text.charAt(i));
}
component.setText(result.toString());
if (haveMnemonic) {
component.setDisplayedMnemonic(mnemonic);
component.setDisplayedMnemonicIndex(mnemonicIndex);
}
}
/**
* @noinspection ALL
*/
private void $$$loadLabelText$$$(JLabel component, String text) {
StringBuffer result = new StringBuffer();
boolean haveMnemonic = false;
char mnemonic = '\0';
int mnemonicIndex = -1;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '&') {
i++;
if (i == text.length()) break;
if (!haveMnemonic && text.charAt(i) != '&') {
haveMnemonic = true;
mnemonic = text.charAt(i);
mnemonicIndex = result.length();
}
}
result.append(text.charAt(i));
}
component.setText(result.toString());
if (haveMnemonic) {
component.setDisplayedMnemonic(mnemonic);
component.setDisplayedMnemonicIndex(mnemonicIndex);
}
}
/**
* @noinspection ALL
*/
private void $$$loadLabelText$$$(JLabel component, String text) {
StringBuffer result = new StringBuffer();
boolean haveMnemonic = false;
char mnemonic = '\0';
int mnemonicIndex = -1;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '&') {
i++;
if (i == text.length()) break;
if (!haveMnemonic && text.charAt(i) != '&') {
haveMnemonic = true;
mnemonic = text.charAt(i);
mnemonicIndex = result.length();
}
}
result.append(text.charAt(i));
}
component.setText(result.toString());
if (haveMnemonic) {
component.setDisplayedMnemonic(mnemonic);
component.setDisplayedMnemonicIndex(mnemonicIndex);
}
}
private void $$$loadLabelText$$$( JLabel component, String text )
{
StringBuffer result = new StringBuffer();
boolean haveMnemonic = false;
char mnemonic = '\0';
int mnemonicIndex = -1;
for( int i = 0; i < text.length(); i++ )
{
if( text.charAt( i ) == '&' )
{
i++;
if( i == text.length() )
{
break;
}
if( !haveMnemonic && text.charAt( i ) != '&' )
{
haveMnemonic = true;
mnemonic = text.charAt( i );
mnemonicIndex = result.length();
}
}
result.append( text.charAt( i ) );
}
component.setText( result.toString() );
if( haveMnemonic )
{
component.setDisplayedMnemonic( mnemonic );
component.setDisplayedMnemonicIndex( mnemonicIndex );
}
}
ControlPanel( SwingInteractivityViewer siv )
{
this.siv = siv;
setLayout( new GridLayout( 0, 1, 0, 0 ) );
JPanel jp = new JPanel( );
jp.setLayout( new FlowLayout( FlowLayout.LEFT, 3, 3 ) );
JLabel choose = new JLabel( "Choose:" );//$NON-NLS-1$
choose.setDisplayedMnemonic( 'c' );
jp.add( choose );
jcbModels = new JComboBox( );
choose.setLabelFor( jcbModels );
jcbModels.addItem( "Highlight Series" );//$NON-NLS-1$
jcbModels.addItem( "Show Tooltip" );//$NON-NLS-1$
jcbModels.addItem( "Toggle Visibility" );//$NON-NLS-1$
jcbModels.addItem( "URL Redirect" );//$NON-NLS-1$
jcbModels.addItem( "Multiple URLs Redirect" );//$NON-NLS-1$
jcbModels.addItem( "Call Back" );//$NON-NLS-1$
jcbModels.addItem( "Right Mouse Click" );//$NON-NLS-1$
jcbModels.addItem( "Mouse Cursor" );//$NON-NLS-1$
jcbModels.setSelectedIndex( 0 );
jp.add( jcbModels );
jbUpdate = new JButton( "Update" );//$NON-NLS-1$
jbUpdate.setMnemonic( 'u' );
jbUpdate.addActionListener( this );
jbUpdate.setToolTipText( "Show" );//$NON-NLS-1$
jp.add( jbUpdate );
add( jp );
}
private void addSearchPanel (JComponent parent)
{
JPanel panel = new JPanel(new FlowLayout(SwingConstants.RIGHT, 0, 0));
JLabel label = new JLabel(getIcon("zoom.png"));
label.setLabelFor(searchTextField);
label.setDisplayedMnemonic('f');
panel.add(label);
panel.add(searchTextField);
parent.add(panel);
}
/**
* Create a JLabel.
*
* @param message Label text with optional mnemonic inside.
* @return Label initialized with text and mnemonic.
*/
public static JLabel createJLabel(String message) {
JLabel label = new JLabel(getLabelWithoutMnemonic(message));
int mnemonic = getMnemonic(message);
if (mnemonic != -1) {
label.setDisplayedMnemonic(mnemonic);
}
return label;
}
ControlPanel( FormatChartsViewer fcv )
{
this.fcv = fcv;
setLayout( new GridLayout( 0, 1, 0, 0 ) );
JPanel jp = new JPanel( );
jp.setLayout( new FlowLayout( FlowLayout.LEFT, 3, 3 ) );
JLabel choose=new JLabel( "Choose:" );//$NON-NLS-1$
choose.setDisplayedMnemonic( 'c' );
jp.add( choose );
jcbModels = new JComboBox( );
jcbModels.addItem( "Axis Format" );//$NON-NLS-1$
jcbModels.addItem( "Colored By Category" );//$NON-NLS-1$
jcbModels.addItem( "Legend & Title Format" );//$NON-NLS-1$
jcbModels.addItem( "Percentage Values" );//$NON-NLS-1$
jcbModels.addItem( "Plot Format" );//$NON-NLS-1$
jcbModels.addItem( "Series Format" );//$NON-NLS-1$
choose.setLabelFor( jcbModels );
jcbModels.setSelectedIndex( 0 );
jp.add( jcbModels );
jbUpdate = new JButton( "Update" );//$NON-NLS-1$
jbUpdate.setMnemonic( 'u' );
jbUpdate.setToolTipText( "Update" );//$NON-NLS-1$
jbUpdate.addActionListener( this );
jp.add( jbUpdate );
add( jp );
}
ControlPanel( DataChartsViewer dcv )
{
this.dcv = dcv;
setLayout( new GridLayout( 0, 1, 0, 0 ) );
JPanel jp = new JPanel( );
jp.setLayout( new FlowLayout( FlowLayout.LEFT, 3, 3 ) );
JLabel choose=new JLabel( "Choose:" );//$NON-NLS-1$
choose.setDisplayedMnemonic( 'c' );
jp.add( choose );
jcbModels = new JComboBox( );
jcbModels.addItem( "Min Slice" );//$NON-NLS-1$
jcbModels.addItem( "Multiple Y Axis" );//$NON-NLS-1$
jcbModels.addItem( "Multiple Y Series" );//$NON-NLS-1$
jcbModels.addItem( "Big number Y Series" );//$NON-NLS-1$
jcbModels.setSelectedIndex( 0 );
choose.setLabelFor( jcbModels );
jp.add( jcbModels );
jbUpdate = new JButton( "Update" );//$NON-NLS-1$
jbUpdate.setMnemonic( 'u' );
jbUpdate.setToolTipText( "Update" );//$NON-NLS-1$
jbUpdate.addActionListener( this );
jp.add( jbUpdate );
add( jp );
}
private void $$$loadLabelText$$$( JLabel component, String text )
{
StringBuffer result = new StringBuffer();
boolean haveMnemonic = false;
char mnemonic = '\0';
int mnemonicIndex = -1;
for( int i = 0; i < text.length(); i++ )
{
if( text.charAt( i ) == '&' )
{
i++;
if( i == text.length() )
{
break;
}
if( !haveMnemonic && text.charAt( i ) != '&' )
{
haveMnemonic = true;
mnemonic = text.charAt( i );
mnemonicIndex = result.length();
}
}
result.append( text.charAt( i ) );
}
component.setText( result.toString() );
if( haveMnemonic )
{
component.setDisplayedMnemonic( mnemonic );
component.setDisplayedMnemonicIndex( mnemonicIndex );
}
}
/** Initializes the Form */
public DDChangesPanel (String caption, final JButton processButton) {
setLayout (new java.awt.BorderLayout (0, 12));
setBorder (new EmptyBorder (12, 12, 11, 0));
JTextArea text = new JTextArea ();
text.setEnabled (false);
text.setEditable (false);
text.setDisabledTextColor (UIManager.getColor ("Label.foreground")); // NOI18N
text.setBackground (UIManager.getColor ("Label.background")); // NOI18N
text.setLineWrap (true);
text.setWrapStyleWord (true);
text.setText (caption);
add (text, "North"); // NOI18N
changesPanel = new JPanel ();
changesPanel.setLayout (new java.awt.BorderLayout (5, 5));
JLabel changesLabel = new JLabel ();
changesLabel.setText (NbBundle.getMessage (DDChangesPanel.class, "LAB_ChangesList"));
changesLabel.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage (DDChangesPanel.class, "ACS_ChangesListA11yDesc")); // NOI18N
changesPanel.add (changesLabel, "North"); // NOI18N
jScrollPane1 = new JScrollPane ();
listModel = new DefaultListModel ();
changesList = new JList (listModel);
changesList.setToolTipText (NbBundle.getMessage (DDChangesPanel.class, "HINT_ChangesList"));
changesList.setCellRenderer (new ChangesListCellRenderer ());
changesList.addListSelectionListener (new ListSelectionListener () {
public void valueChanged (ListSelectionEvent e) {
processButton.setEnabled (!changesList.isSelectionEmpty ());
}
});
changesLabel.setLabelFor (changesList);
changesLabel.setDisplayedMnemonic (NbBundle.getMessage (DDChangesPanel.class, "LAB_ChangesList_Mnemonic").charAt (0));
getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (DDChangesPanel.class, "ACS_ChangesListA11yPanelDesc"));
jScrollPane1.setViewportView (changesList);
changesPanel.add (jScrollPane1, "Center"); // NOI18N
add (changesPanel, "Center"); // NOI18N
}
/** Initializes the Form */
public DDChangesPanel (String caption, final JButton processButton) {
setLayout (new java.awt.BorderLayout (0, 12));
setBorder (new EmptyBorder (12, 12, 11, 0));
JTextArea text = new JTextArea ();
text.setEnabled (false);
text.setEditable (false);
text.setDisabledTextColor (UIManager.getColor ("Label.foreground")); // NOI18N
text.setBackground (UIManager.getColor ("Label.background")); // NOI18N
text.setLineWrap (true);
text.setWrapStyleWord (true);
text.setText (caption);
add (text, "North"); // NOI18N
changesPanel = new JPanel ();
changesPanel.setLayout (new java.awt.BorderLayout (5, 5));
JLabel changesLabel = new JLabel ();
changesLabel.setText (NbBundle.getMessage (DDChangesPanel.class, "LAB_ChangesList"));
changesLabel.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage (DDChangesPanel.class, "ACS_ChangesListA11yDesc")); // NOI18N
changesPanel.add (changesLabel, "North"); // NOI18N
jScrollPane1 = new JScrollPane ();
listModel = new DefaultListModel ();
changesList = new JList (listModel);
changesList.setToolTipText (NbBundle.getMessage (DDChangesPanel.class, "HINT_ChangesList"));
changesList.setCellRenderer (new ChangesListCellRenderer ());
changesList.addListSelectionListener (new ListSelectionListener () {
public void valueChanged (ListSelectionEvent e) {
processButton.setEnabled (!changesList.isSelectionEmpty ());
}
});
changesLabel.setLabelFor (changesList);
changesLabel.setDisplayedMnemonic (NbBundle.getMessage (DDChangesPanel.class, "LAB_ChangesList_Mnemonic").charAt (0));
getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (DDChangesPanel.class, "ACS_ChangesListA11yPanelDesc"));
jScrollPane1.setViewportView (changesList);
changesPanel.add (jScrollPane1, "Center"); // NOI18N
add (changesPanel, "Center"); // NOI18N
}
private void initComponents() {
// Layout description
setLayout(new java.awt.GridBagLayout());
// Entity covers entire row
GridBagConstraints fullRowC = new GridBagConstraints();
fullRowC.gridx = 0;
fullRowC.gridy = 0;
fullRowC.gridwidth = 2;
fullRowC.anchor = GridBagConstraints.WEST;
fullRowC.fill = GridBagConstraints.HORIZONTAL;
fullRowC.insets = new Insets(4, 0, 4, 0);
// Button
GridBagConstraints bC = new GridBagConstraints();
bC.gridx = 1;
bC.gridy = 1;
bC.weightx = 0.1;
bC.fill = GridBagConstraints.HORIZONTAL;
bC.insets = new Insets(4, 20, 4, 0);
// Table panel
GridBagConstraints tableC = new GridBagConstraints();
tableC.gridx = 0;
tableC.gridy = 1;
tableC.gridheight = 4;
tableC.fill = GridBagConstraints.BOTH;
tableC.weightx = 0.9;
tableC.weighty = 1.0;
tableC.anchor = GridBagConstraints.WEST;
tableC.insets = new Insets(4, 0, 4, 0);
// Filler panel
GridBagConstraints fillerC = new GridBagConstraints();
fillerC.gridx = 1;
fillerC.gridy = GridBagConstraints.RELATIVE;
fillerC.fill = GridBagConstraints.BOTH;
fillerC.weighty = 1.0;
fillerC.insets = new Insets(4, 0, 4, 0);
// Component Initialization by row
// 1. Init parameter
jLinitparams = new JLabel(NbBundle.getMessage(InitParamPanel.class, "LBL_initparamsL"));
jLinitparams.setDisplayedMnemonic(NbBundle.getMessage(InitParamPanel.class, "LBL_initparams_mnemonic").charAt(0));
// PENDING
this.add(jLinitparams, fullRowC);
// 2. Table row
String[] headers = {"paramname", "paramvalue"};
table = new DDTable(headers, "LBL_initparams", Editable.BOTH);
jLinitparams.setLabelFor(table);
// Enable the buttons according to the row selected
table.getSelectionModel().addListSelectionListener(this);
table.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InitParamPanel.class, "ACSD_initparams_desc")); // NOI18N
table.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InitParamPanel.class, "ACSD_initparams")); // NOI18N
table.getModel().addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent evt) {
updateInitParams();
}
});
scrollP = new JScrollPane(table);
this.add(scrollP, tableC);
jBnew = new JButton();
jBnew.setText(NbBundle.getMessage(InitParamPanel.class, "LBL_new"));
jBnew.setMnemonic(NbBundle.getMessage(InitParamPanel.class, "LBL_new_mnemonic").charAt(0));
jBnew.addActionListener(this);
jBnew.setActionCommand(ADD);
jBnew.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InitParamPanel.class, "ACSD_initparam_new")); // NOI18N
this.add(jBnew, bC);
bC.gridy++;
jBedit = new JButton();
jBedit.setText(NbBundle.getMessage(InitParamPanel.class, "LBL_edit"));
jBedit.setMnemonic(NbBundle.getMessage(InitParamPanel.class, "LBL_edit_mnemonic").charAt(0));
jBedit.addActionListener(this);
jBedit.setActionCommand(EDIT);
jBedit.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InitParamPanel.class, "ACSD_initparam_edit")); // NOI18N
jBedit.setEnabled(false);
this.add(jBedit, bC);
bC.gridy++;
jBdelete = new JButton();
jBdelete.setText(NbBundle.getMessage(InitParamPanel.class, "LBL_delete"));
jBdelete.setMnemonic(NbBundle.getMessage(InitParamPanel.class, "LBL_delete_mnemonic").charAt(0));
jBdelete.addActionListener(this);
jBdelete.setActionCommand(REMOVE);
jBdelete.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InitParamPanel.class, "ACSD_initparam_delete")); // NOI18N
jBdelete.setEnabled(false);
this.add(jBdelete, bC);
this.add(new javax.swing.JPanel(), fillerC);
}
public void performAction () {
ResourceBundle bundle = NbBundle.getBundle (AddJspWatchAction.class);
JPanel panel = new JPanel();
panel.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_WatchPanel")); // NOI18N
JTextField textField;
JLabel textLabel = new JLabel (bundle.getString ("CTL_Watch_Name")); // NOI18N
textLabel.setBorder (new EmptyBorder (0, 0, 0, 10));
panel.setLayout (new BorderLayout ());
panel.setBorder (new EmptyBorder (11, 12, 1, 11));
panel.add ("West", textLabel); // NOI18N
panel.add ("Center", textField = new JTextField (25)); // NOI18N
textField.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_CTL_Watch_Name")); // NOI18N
textField.setBorder (
new CompoundBorder (textField.getBorder (),
new EmptyBorder (2, 0, 2, 0))
);
textLabel.setDisplayedMnemonic (
bundle.getString ("CTL_Watch_Name_Mnemonic").charAt (0) // NOI18N
);
String t = null;//Utils.getELIdentifier();
// Utils.log("Watch: ELIdentifier = " + t);
boolean isScriptlet = Utils.isScriptlet();
Utils.log("Watch: isScriptlet: " + isScriptlet);
if ((t == null) && (isScriptlet)) {
t = Utils.getJavaIdentifier();
Utils.log("Watch: javaIdentifier = " + t);
}
if (t != null) {
textField.setText(t);
} else {
textField.setText(watchHistory);
}
textField.selectAll ();
textLabel.setLabelFor (textField);
textField.requestFocus ();
org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor (
panel,
bundle.getString ("CTL_Watch_Title") // NOI18N
);
dd.setHelpCtx (new HelpCtx ("debug.add.watch"));
Dialog dialog = DialogDisplayer.getDefault ().createDialog (dd);
dialog.setVisible(true);
dialog.dispose ();
if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION) return;
String watch = textField.getText();
if ((watch == null) || (watch.trim ().length () == 0)) {
return;
}
String s = watch;
int i = s.indexOf (';');
while (i > 0) {
String ss = s.substring (0, i).trim ();
if (ss.length () > 0)
DebuggerManager.getDebuggerManager ().createWatch (ss);
s = s.substring (i + 1);
i = s.indexOf (';');
}
s = s.trim ();
if (s.length () > 0)
DebuggerManager.getDebuggerManager ().createWatch (s);
watchHistory = watch;
// open watches view
// new WatchesAction ().actionPerformed (null); TODO
}
/**
* Sets the resources on a {@link JLabel}. It sets the text, mnemonic,
* and labelFor property.
*
* @param label The Label on which to set the properties
* @param labelFor the {@link Component} to set with the
* <code>labelFor</code> property on the <code>label</code>.
* @param labelText The text label to set on the <code>label</code>
* @see JLabel#setText(String)
* @see JLabel#setLabelFor(Component)
* @see JLabel#setDisplayedMnemonic(int)
*/
public static void resLabel(JLabel label, Component labelFor, String labelText) {
label.setText(stripMnemonic(labelText));
if (Spark.isWindows()) {
label.setDisplayedMnemonic(getMnemonicKeyCode(labelText));
}
label.setLabelFor(labelFor);
}