-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0
-
generic
-
generic
JFileChooser.setApproveButtonText() sets the title of the filechooser's
dialog in addition to the text of the approve button.
The following application demonstrates this.
================================================
/*
* JFileChooserTest.java
* JFileChooser.setApproveButtonText() sets the title of the filechooser's
* dialog in addition to the text of the approve button
*
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JFileChooserTest extends JPanel implements ActionListener {
JFrame f = new JFrame ();
JPanel infoPanel = new JPanel ();
JPanel p1 = new JPanel ();
JPanel p2 = new JPanel ();
JButton b = new JButton ("Show JFileChooser");
JFileChooser fchooser = new JFileChooser();
JTextField approveButtonText = new JTextField();
public JFileChooserTest() {
f.addWindowListener (new WindowAdapter () {
public void windowClosing (WindowEvent e)
{
f.dispose ();
System.exit (0);
}
});
f.getContentPane().setLayout (new BorderLayout());
infoPanel.setLayout (new GridLayout(0,1));
p1.setLayout (new FlowLayout());
p2.setLayout (new FlowLayout());
p1.setBackground (Color.white);
p2.setBackground (Color.pink);
p1.add (b);
approveButtonText.setToolTipText("Invokes JFileChooser.setApproveButtonText().");
approveButtonText.setPreferredSize(new Dimension(250,25));
approveButtonText.setActionCommand("Approve button text");
p2.add (new JLabel("Approve button text: "));
p2.add (approveButtonText);
infoPanel.add (new JLabel("JFileChooser.setApproveButtonText() sets the title of the filechooser's dialog"));
infoPanel.add (new JLabel("in addition to the text of the approve button."));
infoPanel.add (new JLabel("Enter text in the textfield and press <ENTER> or <RETURN> to set the approve button's text."));
infoPanel.add (new JLabel(""));
f.getContentPane().add (BorderLayout.NORTH, infoPanel);
f.getContentPane().add (BorderLayout.CENTER, p1);
f.getContentPane().add (BorderLayout.SOUTH, p2);
f.setTitle("JFileChooser.setApproveButtonText() Test");
f.pack();
f.setSize (730, 300);
f.setVisible(true);
b.addActionListener(this);
approveButtonText.addActionListener(this);
}
public void actionPerformed(ActionEvent evt) {
String command = evt.getActionCommand();
if (command == "Show JFileChooser")
fchooser.showOpenDialog(this);
else if (command == "Approve button text")
fchooser.setApproveButtonText(approveButtonText.getText());
}
public static void main (String[] args) {
new JFileChooserTest();
}
}
================================================
- duplicates
-
JDK-4176366 JFileChooser: Default dialog title should not be approve button label
- Closed