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:
public class 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;
}
public static void 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:
public void 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