Solved

Increasing the button size of showConfirmDialog and showMessageDialog

Posted on 2004-09-16
11
1,064 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
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 step-by-step guide to install VisualVM launcher in eclipse.

691 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