Results 1 to 2 of 2
  1. #1
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Buttons from the PLAF

    I want to use buttons in my own dialogs that have the same text and mnemonics as those on standard JOptionPane dialogs. Some kind of standard ButtonFactory would be ideal, but I don't think it exists.

    As my plan B, I tried getting the button text and mnemonic from the UIManager. The key "OptionPane.yesButtonText" gives me the text for the yes button, but "OptionPane.yesButtonMnemonic" always gives me null. And yet, if I show a standard yes/no JOptionPane, its buttons have mnemonics. Where is it getting them? I tried looking at the code, but JOptionPane#setOptionType(int) just fires off a property change. I can't find what receives that property change and actually changes the buttons. Any ideas?
    Get in the habit of using standard Java naming conventions!

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Buttons from the PLAF

    Nevermind. I'm going to turn my JDialog into a JPanel and use it as the message of a JOptionPane.

    Java Code:
    package test;
    
    import java.awt.Color;
    import java.awt.Dimension;
    
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    
    public class JBoogerPane {
    
    	public static void main(String[] args) {
    		SwingUtilities.invokeLater(new Runnable() {
    			@Override
    			public void run() {
    				JPanel panel = new JPanel();
    				panel.setPreferredSize(new Dimension(300, 200));
    				panel.setBackground(Color.GREEN);
    				JOptionPane.showConfirmDialog(null, panel, "Boogers", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE);				
    			}
    		});
    	}
    }
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Set Buttons on top of each other
    By Taylor91 in forum AWT / Swing
    Replies: 4
    Last Post: 11-21-2012, 05:38 AM
  2. Replies: 4
    Last Post: 10-25-2012, 03:25 PM
  3. Help with Buttons
    By wld4ubabay in forum New To Java
    Replies: 20
    Last Post: 05-17-2010, 09:13 AM
  4. Where To Get Pop Up Buttons
    By hitmen in forum AWT / Swing
    Replies: 7
    Last Post: 03-26-2009, 05:05 AM
  5. How to use SWT Buttons
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 05:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •