下面列出了javax.swing.JFormattedTextField#setToolTipText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public DatePickerPanel() {
super();
setLayout(new GridLayout(1 /* rows */, 3 /* cols */));
yearTextField = new JFormattedTextField();
yearTextField.setToolTipText("Year (YYYY)");
yearTextField.addActionListener(this);
add(yearTextField);
monthTextField = new JFormattedTextField();
monthTextField.setToolTipText("Month (MM)");
monthTextField.addActionListener(this);
add(monthTextField);
dayTextField = new JFormattedTextField();
dayTextField.setToolTipText("Day (DD)");
dayTextField.addActionListener(this);
add(dayTextField);
dateConsumers = new ArrayList<>();
}
public void setFilePath(JFormattedTextField textField){
//begin with creation of new file
JFileChooser fc = new JFileChooser();
//set directory and ".log" filter
fc.setCurrentDirectory(new File(System.getProperty("user.dir")));
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setFileFilter(logFileFilter_);
int status = fc.showDialog(this, Messages.getString("EditLogControlPanel.approveButton"));
if(status == JFileChooser.APPROVE_OPTION){
textField.setValue(fc.getSelectedFile().getAbsolutePath());
textField.setToolTipText(fc.getSelectedFile().getAbsolutePath());
textField.setCaretPosition(textField.getText().length());
}
}
public static JFormattedTextField createDateField(JPanel pnl, String str, String tip) {
SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
JFormattedTextField txt = new JFormattedTextField(format);
txt.setText(str);
txt.setToolTipText(tip);
pnl.add(txt);
return txt;
}
@Override
public List< ? extends Component> createBrickComponents() {
List<Component> components = new ArrayList<Component>();
// tooltip
String tooltip = control.getTooltip();
// label
if ( control.getLabel() != null ) {
label = new JLabel();
label.setName(getName()+"/label");
label.setText(control.getLabel());
if ( tooltip != null ) label.setToolTipText( tooltip );
}
// textField
textField = new JFormattedTextField();
textField.setName(getName()+"/text");
// init value
if ( ControlHelper.getInitValue( control, getAtdl4jOptions() ) != null )
textField.setText( (String) ControlHelper.getInitValue( control, getAtdl4jOptions() ) );
// tooltip
if (tooltip != null) textField.setToolTipText(tooltip);
if (label != null){
components.add( label);
}
components.add( textField);
textField.setPreferredSize(new Dimension(100, textField.getPreferredSize().height));
return components;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jCoordinateNameLabel = new javax.swing.JLabel();
jXSlider = new javax.swing.JSlider();
jFormattedTextField = new JFormattedTextField(formatter);
jMinimumLabel = new javax.swing.JLabel();
jMaximumLabel = new javax.swing.JLabel();
jCoordinateNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jCoordinateNameLabel.setText("coordinate");
jCoordinateNameLabel.setToolTipText("Name");
jCoordinateNameLabel.setAlignmentX(1.0F);
jCoordinateNameLabel.setMaximumSize(new java.awt.Dimension(100, 14));
jCoordinateNameLabel.setMinimumSize(new java.awt.Dimension(100, 14));
jCoordinateNameLabel.setPreferredSize(new java.awt.Dimension(100, 14));
setBorder(javax.swing.BorderFactory.createTitledBorder("Slider label"));
setAlignmentY(0.0F);
jXSlider.setMajorTickSpacing(20);
jXSlider.setMinorTickSpacing(10);
jXSlider.setToolTipText("Seek");
jXSlider.setAlignmentX(0.0F);
jXSlider.setMinimumSize(new java.awt.Dimension(50, 25));
jXSlider.setPreferredSize(new java.awt.Dimension(50, 25));
jFormattedTextField.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
jFormattedTextField.setText("-123.456");
jFormattedTextField.setToolTipText("Current value");
jFormattedTextField.setFont(new java.awt.Font("Tahoma", 0, 11));
jFormattedTextField.setMinimumSize(new java.awt.Dimension(55, 19));
jFormattedTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jFormattedTextFieldActionPerformed(evt);
}
});
jMinimumLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jMinimumLabel.setText("-123");
jMinimumLabel.setToolTipText("Lower bound");
jMinimumLabel.setFocusable(false);
jMinimumLabel.setIconTextGap(0);
jMinimumLabel.setMaximumSize(new java.awt.Dimension(30, 25));
jMinimumLabel.setMinimumSize(new java.awt.Dimension(30, 25));
jMinimumLabel.setPreferredSize(new java.awt.Dimension(30, 25));
jMaximumLabel.setText("123");
jMaximumLabel.setToolTipText("Upper bound");
jMaximumLabel.setFocusable(false);
jMaximumLabel.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
jMaximumLabel.setIconTextGap(0);
jMaximumLabel.setMaximumSize(new java.awt.Dimension(25, 25));
jMaximumLabel.setMinimumSize(new java.awt.Dimension(25, 25));
jMaximumLabel.setPreferredSize(new java.awt.Dimension(25, 25));
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jFormattedTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 55, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jMinimumLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jXSlider, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jMaximumLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jMaximumLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jFormattedTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jMinimumLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jXSlider, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
);
}
protected void installComponents() {
field = new JFormattedTextField(createFormatterFactory());
field.setValue(peer.getDate());
field.setFocusLostBehavior(peer.getFocusLostBehavior());
field.setEditable(peer.isFieldEditable());
field.setToolTipText(peer.getToolTipText());
// button
button = new JButton();
button.setFocusable(false);
button.setMargin(new Insets(0, 0, 0, 0));
button.setToolTipText(peer.getToolTipText());
setSimpeLook(false);
// calendar
calendarPane = new CalendarPane(peer.getStyle());
calendarPane.setShowTodayButton(peer.isShowTodayButton());
calendarPane.setFocusLostBehavior(JFormattedTextField.REVERT);
calendarPane.setFocusCycleRoot(true);
calendarPane.setBorder(BorderFactory.createEmptyBorder(1, 3, 0, 3));
calendarPane.setStripTime(false);
calendarPane.setLocale(peer.getLocale());
calendarPane.setZone(peer.getZone());
calendarPane.setFocusable(peer.isDropdownFocusable());
calendarPane.setColorOverrideMap(peer.getColorOverrideMap());
// popup
popup = new JPopupMenu();
popup.setLayout(new BorderLayout());
popup.add(calendarPane, BorderLayout.CENTER);
popup.setLightWeightPopupEnabled(true);
// add
peer.setLayout(new BorderLayout());
switch (peer.getPickerStyle()) {
case DatePicker.PICKER_STYLE_FIELD_AND_BUTTON:
peer.add(field, BorderLayout.CENTER);
peer.add(button, BorderLayout.EAST);
break;
case DatePicker.PICKER_STYLE_BUTTON:
peer.add(button, BorderLayout.EAST);
break;
}
peer.revalidate();
peer.repaint();
componentListener = new ComponentListener();
button.addActionListener(componentListener);
field.addPropertyChangeListener(componentListener);
calendarPane.addPropertyChangeListener(componentListener);
calendarPane.addCommitListener(componentListener);
calendarPane.addActionListener(componentListener);
peerDateChanged(peer.getDate());
}
public void createWidget(JPanel parent)
{
// tooltip
String tooltip = control.getTooltip();
// label
if ( control.getLabel() != null ) {
label = new JLabel();
label.setName(getName()+"/label");
label.setText(control.getLabel());
if ( tooltip != null ) label.setToolTipText( tooltip );
}
// textField
textField = new JFormattedTextField();
textField.setName(getName()+"/text");
// init value
if ( ControlHelper.getInitValue( control, getAtdl4jOptions() ) != null )
textField.setText( (String) ControlHelper.getInitValue( control, getAtdl4jOptions() ) );
// tooltip
if (tooltip != null) textField.setToolTipText(tooltip);
if (label != null){
wrapper = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 1;
c.weightx = 1.0;
c.weighty = 1.0;
c.insets = new Insets(0, 0, 0, 0);
wrapper.add( label, c);
c.gridx = 1;
c.gridy = 0;
c.insets = new Insets(0, 0, 0, 0);
wrapper.add( textField, c);
parent.add(wrapper);
}
else {
parent.add(textField);
}
textField.setPreferredSize(new Dimension(100, textField.getPreferredSize().height));
textField.revalidate();
}