Link to home
Start Free TrialLog in
Avatar of Howie_Ly
Howie_LyFlag for Australia

asked on

Hide/remove maximize button on JFrame.

G'day everyone.

I have a JFrame which I wish to remove or completely hide the Maximize button (on top right hand corner) yet leave the Minimize and Close buttons still showing.

I've tried a few things such as setting resizable to false ( frame.setResizable(false); ) but that just seems to disable the button not hide it completely.

I have also tried using a JDialog instead of a JFrame but that seems to just show the close button, not the minimize.

Points to anyone who can show me the code to achieve what i want.

Cheers!

Howie
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Think you'll need to handle painting the title bar yourself to achieve that.
Avatar of Howie_Ly

ASKER

Hi objects.  I did suspect as much.

Seems like such a simple thing though..  have you stumbled upon any code which will help me?
ASKER CERTIFIED SOLUTION
Avatar of Javatm
Javatm
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Javatm, I've just had a play with JInternalFrame and as you said it does remove the minimize button.

But the main window remains open when you click minimize and close... are you suggesting i catch the event and pass it over to the parent?  also i can't seem to find where i get rid of the title bar from the parent frame.  One more thing, i have a LAF and it renders internal frames quite ugly...

I still prefer Object's proposed method at this stage.. as to avoid the above complications.  Just like someone to post some code on how to get that working.

Try this :

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Word extends JWindow {

 public Word()
  {
  super("Word Processor . . .");
 
  JDesktopPane p1 = new JDesktopPane();
  JInternalFrame f1 = new JInternalFrame("",false,true,false,true);

  JTextArea txt1 = new JTextArea();
  txt1.setSize(300,300);

  f1.add(new JScrollPane(txt1));
  f1.show();
  p1.add(f1);
   
  getContentPane().setLayout( new BorderLayout() );
  getContentPane().add( p1, BorderLayout.CENTER);

  setSize(500, 500);
  show();
  }

 public static void main (String args[])
  {
   Word x = new Word();
   x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
 }
Sorry I remebered that we are JWindow for us to remove the Titlebar
Its like this actually :

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Word extends JWindow {

 public Word()
  {
  JDesktopPane p1 = new JDesktopPane();
  JInternalFrame f1 = new JInternalFrame("Sample . . .",false,true,false,true);

  JTextArea txt1 = new JTextArea();
  txt1.setSize(300,300);

  f1.add(new JScrollPane(txt1));
  f1.show();
  p1.add(f1);
   
  getContentPane().setLayout( new BorderLayout() );
  getContentPane().add( p1, BorderLayout.CENTER);

  setSize(500, 500);
  show();
  }

 public static void main (String args[])
  {
      Word x = new Word();

      x.addWindowListener(
         new WindowAdapter() {
            public void windowClosing( WindowEvent e )
            {
               System.exit( 0 );
            }
         }
       );
    }
 }
If you want to close the entire program just click on the "x" mark on the
Internal Frame w/ this codes :

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Word extends JWindow {

 public Word()
  {
  JDesktopPane p1 = new JDesktopPane();
  JInternalFrame f1 = new JInternalFrame("Sample . . .",false,true,false,true);

  JTextArea txt1 = new JTextArea();
  txt1.setSize(300,300);

  f1.add(new JScrollPane(txt1));
  f1.show();
  p1.add(f1);

  f1.setDefaultCloseOperation(JInternalFrame.EXIT_ON_CLOSE);
   
  getContentPane().setLayout( new BorderLayout() );
  getContentPane().add( p1, BorderLayout.CENTER);

  setSize(500, 500);
  show();
  }

 public static void main (String args[])
  {
      Word x = new Word();
  }
 }
>> I still prefer Object's proposed method at this stage.. as to avoid the above complications

    As what Object said " Think you'll need to handle painting the title bar yourself ".

    This is hard to do thats why I'm giving you a much easier way.