Remove Minimize,Maximize and Close Button From a Jframe

Hi,

I need to create a screen which doesnt have minimize,maximize and close buttons on the top right corner. In one of the forums I found this as a solution:

jFrame.setUndecorated(true);

jFrame.getRootPane().

setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);

When I write this in a class and run it it works fine (I get a jframe without the 3 buttons and am able to move the frame and maximize it when I double click on the tilte bar)

However, If i try to call this class from the actionperformed method of a JButton in another class I do not get desired results.It creates a "Window" which cant be moved and cant be maximised.

Please help.

Here is the code:

Class where it works fin when the class is run separately:

publicclass Testing{

private JPanel jContentPane =null;

private JFrame jFrame =null;// @jve:decl-index=0:visual-constraint="144,75"

private JPanel jPanel =null;

private JTextField jTextField =null;

/**

* This method initializes jContentPane

*

* @return javax.swing.JPanel

*/

private JPanel getJContentPane(){

if (jContentPane ==null){

jContentPane =new JPanel();

jContentPane.setLayout(new BorderLayout());

jContentPane.add(getJPanel(),null);

}

return jContentPane;

}

/**

* This method initializes jFrame

*

* @return javax.swing.JFrame

*/

public JFrame getJFrame(){

if (jFrame ==null){

//JFrame.setDefaultLookAndFeelDecorated(true);

jFrame =new JFrame();

jFrame.setContentPane(getJContentPane());

jFrame.setSize(403, 239);

jFrame.setTitle("jFrame");

jFrame.setUndecorated(true);

jFrame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);

}

return jFrame;

}

/**

* This method initializes jPanel

*

* @return javax.swing.JPanel

*/

private JPanel getJPanel(){

if (jPanel ==null){

jPanel =new JPanel();

jPanel.setLayout(new BorderLayout());

jPanel.setBounds(50, 33, 325, 146);

jPanel.add(getJTextField(),null);

}

return jPanel;

}

/**

* This method initializes jTextField

*

* @return javax.swing.JTextField

*/

private JTextField getJTextField(){

if (jTextField ==null){

jTextField =new JTextField();

jTextField.setBounds(58, 45, 242,47);

}

return jTextField;

}

publicstaticvoid main(String[] args)

{

Testing t =new Testing();

t.getJFrame().setSize(400,400);

t.getJFrame().setVisible(true);

}

}

==================================================

Here is the code where it is called in the actionPerformed method in another class:

publicvoid actionPerformed(ActionEvent ae)

{

if(ae.getSource() == jButton1)

{

Testing t =new Testing();

t.getJFrame().setSize(400,400);

t.getJFrame().setVisible(true);

}

This is where it fails

[5444 byte] By [annie.123a] at [2007-11-27 8:30:58]
# 1

I am unable to reproduce your problem. But I would propose a few simplifications to your code, like e.g. like having your class extend JPanel. Here's a proposition:import java.awt.BorderLayout;

import javax.swing.JFrame;

import javax.swing.JRootPane;

public class Testing extends JFrame {

public Testing() {

setDefaultLookAndFeelDecorated(true);

setLayout(new BorderLayout());

setSize(403, 239);

setTitle("jFrame");

setUndecorated(true);

getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);

}

public static void main(String[] args) {

Testing t = new Testing();

t.setSize(400,400);

t.setVisible(true);

}

}

Does the problem still occur with this code?

Oh, and by the way, I still get the close button in that frame (but not the minimize and the maximize).

rebola at 2007-7-12 20:26:15 > top of Java-index,Desktop,Core GUI APIs...
# 2
Hi rebol,The problem still exists when I try to call the frame from another class.. When the frame is run on its own as a separate class it works fine....
annie.123a at 2007-7-12 20:26:15 > top of Java-index,Desktop,Core GUI APIs...