Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JDialog closing resizing and minimizing

Posted on 2004-08-03
17
Medium Priority
?
5,241 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 800 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 800 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 600 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 200 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 200 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 200 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 600 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

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!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

772 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