Solved

JDialog closing resizing and minimizing

Posted on 2004-08-03
17
4,945 Views
Last Modified: 2012-05-05
I'm creating a custom dialog box by extending JDialog.
I was wondering whether it was possible to cause the close, resize, and minimize buttons to disappear. Not just disable them, but actually have them _not_ appear
Thanks
0
Comment
Question by:carlos_jjang
[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
  • 6
  • 4
  • 3
  • +3
17 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11708300
Integrating MFC with Java will give such type of results
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11708357
if you use jwindow all you get is an empty container, no min,max, close buttons, and no window/frame border.

do you wish do contruct your own window/frame? if so, its gets tricky
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11708375
try this also:

JDialog dlg = new JDialog(owner) ;
dlg.setUndecorated(true);
dlg.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
dlg.setTitle("Plain");
dlg.setSize( new Dimension(320, 200));
dlg.show();
0
Industry Leaders: 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 14

Accepted Solution

by:
sudhakar_koundinya earned 200 total points
ID: 11708400
from http://www.objects.com.au/java/examples/swing/PlainDialog.do

/*
*  Copyright (c) 2004 by Object Pty Ltd
*/

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

/**
*  Example showing how popup a dialog without any buttons on title bar.
*
*  @author Mick Barry http://www.objects.com.au
*/

public class PlainDialogExample
{
      public static void main(String[] args)
      {
            JDialog dialog = new JDialog((JFrame)null, "Plain Dialog") ;
            dialog.setUndecorated(true);
            dialog.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
            
            JButton close = new JButton("Close");
            close.addActionListener(new ActionListener()
            {
                  public void actionPerformed(ActionEvent e)
                  {
                        System.exit(0);
                  }
            });
            
            dialog.getContentPane().add(close, BorderLayout.SOUTH);
            
            dialog.setSize(320, 200);
            dialog.show();
      }
}
0
 
LVL 14

Assisted Solution

by:sudhakar_koundinya
sudhakar_koundinya earned 200 total points
ID: 11708446
JWindow window = new JWindow();
   
    // Add component to the window
    window.getContentPane().add(close, BorderLayout.CENTER);
   
    // Set initial size
    window.setSize(300, 300);
   
    // Show the window
    window.setVisible(true);
0
 
LVL 15

Assisted Solution

by:Javatm
Javatm earned 150 total points
ID: 11710575
> I'm creating a custom dialog box by extending JDialog. I was wondering whether it was
> possible to cause the close, resize, and minimize buttons to disappear.

Actually here's a better way of doing it extend it to JWindow :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class FrameLessDialog extends JWindow {

  private JButton b1;
  private JPanel p1;

  public FrameLessDialog() {

  super("FrameLess Example . . .");

  b1 = new JButton();
  p1 = new JPanel();
  p1.add(b1);

  getContentPane().add(p1, BorderLayout.CENTER);

  // Center To Screen . . .
  Dimension sd = Toolkit.getDefaultToolkit().getScreenSize();
  setLocation(sd.width / 2 - 300 / 2,
  sd.height / 2 - 300 / 2);

  setSize(300, 300);
  setVisible(true);

  b1.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e)
  {
  System.exit(0);
  }
  });
  }

  public static void main(String args[]) {
  FrameLessDialog x = new FrameLessDialog();
  }
}

Hope that helps . . .
Javatm
0
 
LVL 92

Assisted Solution

by:objects
objects earned 50 total points
ID: 11710881
sudhakar_koundinya , Nice example :-)
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11710910
that was ur's example only. I always navigate ur site to see the latest developments of ur company :-)
0
 
LVL 92

Expert Comment

by:objects
ID: 11710948
If you ever have any good suggestions for new examples let me know and I'll see what I can do
0
 
LVL 15

Expert Comment

by:Javatm
ID: 11711031
>  If you ever have any good suggestions for new examples let me know and I'll see what I can do

Maybe a good suggestion would be learning to customize a certain objects, One good example
would be a customize JTextComponent.
0
 

Assisted Solution

by:dubbs2003
dubbs2003 earned 50 total points
ID: 11711780
// This should do the trick.  This code creates a new JDialog window
// without a title bar, so no resize, maximize and close buttons.

public class JDialog extends javax.swing.JDialog {
   
    public JDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
   
    private void initComponents() {
        getContentPane().setLayout(null);
        setTitle("Title");
        setUndecorated(true);
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
    }
   
    public static void main(String args[]) {
        new JDialog(new javax.swing.JFrame(), true).show();
    }
}
0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 50 total points
ID: 11712744
Just a remark for Javatm:

This:
        // Center To Screen . . .
        Dimension sd = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(sd.width / 2 - 300 / 2, sd.height / 2 - 300 / 2);

can be replaced by:

        setLocationRelativeTo(null);
0
 
LVL 15

Expert Comment

by:Javatm
ID: 11721545
Gee's one new method learned, on what java version did they
started to release it ? Thanks for that !.
0
 
LVL 15

Assisted Solution

by:Javatm
Javatm earned 150 total points
ID: 11721593
I tried using that in 1.5 but instead of going to center of the monitor its 2 inches
left and down ??? why is that happening ?

I've been using this for a long time and it never fails me.

// Center To Screen . . .
Dimension sd = Toolkit.getDefaultToolkit().getScreenSize();
setLocation(sd.width / 2 - 300 / 2, sd.height / 2 - 300 / 2);

0
 
LVL 37

Expert Comment

by:zzynx
ID: 11723793
>>on what java version did they started to release it ?
the doc says since 1.4

>> I tried using that in 1.5 but ...??? why is that happening ?
Don't know. I stick to 1.4.2 for the moment.
0
 

Author Comment

by:carlos_jjang
ID: 11738426
Thanks for all the help!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 11739759
Thanks for accepting.

P.S.
You really don't *need* to split between all, you know.
But of course you're allowed to. ;°)
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

734 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