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
Solved

Increasing the button size of showConfirmDialog and showMessageDialog

Posted on 2004-09-16
11
970 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
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 50 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
more than one jdk and one jre 1 50
hibernate insert example 13 34
eclipse console opening separately 2 29
Java basic valueOf question 1 29
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

840 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