• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5392
  • Last Modified:

JDialog closing resizing and minimizing

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
carlos_jjang
Asked:
carlos_jjang
  • 6
  • 4
  • 3
  • +3
7 Solutions
 
sudhakar_koundinyaCommented:
Integrating MFC with Java will give such type of results
0
 
sudhakar_koundinyaCommented:
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
 
sudhakar_koundinyaCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
sudhakar_koundinyaCommented:
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
 
sudhakar_koundinyaCommented:
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
 
JavatmCommented:
> 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
 
objectsCommented:
sudhakar_koundinya , Nice example :-)
0
 
sudhakar_koundinyaCommented:
that was ur's example only. I always navigate ur site to see the latest developments of ur company :-)
0
 
objectsCommented:
If you ever have any good suggestions for new examples let me know and I'll see what I can do
0
 
JavatmCommented:
>  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
 
dubbs2003Commented:
// 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
 
zzynxSoftware engineerCommented:
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
 
JavatmCommented:
Gee's one new method learned, on what java version did they
started to release it ? Thanks for that !.
0
 
JavatmCommented:
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
 
zzynxSoftware engineerCommented:
>>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
 
carlos_jjangAuthor Commented:
Thanks for all the help!
0
 
zzynxSoftware engineerCommented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 6
  • 4
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now