?
Solved

Increasing the button size of showConfirmDialog and showMessageDialog

Posted on 2004-09-16
11
Medium Priority
?
1,117 Views
Last Modified: 2008-01-16
hi,
 How to increase the size of YES_NO Button and OK Button of showConfirmDialog and showMessageDialog respectively.  Now it seems to be very small width and height when we view through 1024 resolution screen.

Regards

Anitha S
0
Comment
Question by:anithas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
11 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12073541
Set "____Yes____" and "____No____" on that buttons  (with _ being a blank)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12073544
That's for the width of course
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12073643
I mean

          Object[] options = { "       Yes        ", "       No       " };
          JOptionPane.showOptionDialog(null, "Are you sure to .... ?", "Title",
                 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
                 null, options, options[0]);
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 37

Expert Comment

by:zzynx
ID: 12073653
>> Now it seems to be very small width and height when we view through 1024 resolution screen.
I think it will follow the system's look and feel. So, not sure if it's a good idea to change that.
0
 
LVL 37

Accepted Solution

by:
zzynx earned 200 total points
ID: 12073721
Here's what you want:

/*
 * JOptionPaneDemo.java
 *
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
 *
 * @author  zzynx
 */
public class JOptionPaneDemo extends JFrame {
   
    public JOptionPaneDemo() {
        init();
        setSize(500, 400);
        setLocationRelativeTo(null);
    }

    private void init() {
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                System.exit(0);
            }
        });
       
        JButton button = new JButton("Go");
        button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonActionPerformed(evt);
            }
        });
       
        getContentPane().setLayout(new FlowLayout());
        getContentPane().add(button);
       
        pack();
    }
   
    private void buttonActionPerformed(java.awt.event.ActionEvent evt) {
        JOptionPane p = new JOptionPane("Are you sure you want to log out?",
            JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
        // Get the first button:
        JButton bYes = (JButton)((JPanel)p.getComponent(1)).getComponent(0);
        // Set it's preferred size
        // Remark: by setting the width of one, the other will follow.
        // To see what I mean comment out the line marked with /*[x]*/
        bYes.setPreferredSize( new Dimension(150, 40) );
        JButton bNo = (JButton)((JPanel)p.getComponent(1)).getComponent(1);
        bNo.setPreferredSize( new Dimension(150, 40) );  /*[x]*/
        final JDialog d = p.createDialog(this, "Report");
        FocusListener fl= new FocusAdapter() {
            public void focusGained(FocusEvent e) {
                JButton focusButton= (JButton)(e.getSource());
                d.getRootPane().setDefaultButton(focusButton);      
            }    
        };
        bYes.addFocusListener(fl);
        bNo.addFocusListener(fl);
        d.setLocationRelativeTo(this);
       
        bNo.requestFocus(); // <<< Set the default button here
        d.setVisible(true);
        Object value = p.getValue();
        if (value == null || !(value instanceof Integer)) {
            JOptionPane.showMessageDialog(null, "You closed without answering");
        }
        else    {
            int i = ((Integer)value).intValue();
            if (i == JOptionPane.DEFAULT_OPTION) {
                JOptionPane.showMessageDialog(null, "You pressed ESC");
            }
            else if (i == JOptionPane.NO_OPTION) {
                JOptionPane.showMessageDialog(null, "You choose \"No\"");
            } else if (i == JOptionPane.YES_OPTION) {
                JOptionPane.showMessageDialog(null, "You choose \"Yes\"");
            }
        }
    }

    public static void main(String args[]) {
        JOptionPaneDemo f = new JOptionPaneDemo();
        f.show();
    }
   
}
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12074878
You can also get what you want by:

   Font buttonFont = new Font("Ms Sans Serif", Font.BOLD, 12);

               UIManager.put("Button.font", buttonFont);

Then ALL buttons get the new font; you can choose another or bigger font if you like.

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12284257
Please split.
;JOOP!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12284333
Sorry sciuriware, but I really think my last comment is the solution.
(S)he asked for an increase of the button sizes. (S)he didn't told (s)he wants the font to be bigger.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12284474
mmmmmmmmmmmmmmm
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12285076
Thank you
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question