Solved

JDialog closing resizing and minimizing

Posted on 2004-08-03
17
4,736 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
triangle challenge 4 77
Updating Java 9 87
strDist challenge 35 84
DO we need Java installed on a Windows PC and WHY ? 13 78
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…
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 …
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now