Solved

Hide/remove maximize button on JFrame.

Posted on 2003-11-18
8
7,000 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:Howie_Ly
  • 5
  • 2
8 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
Think you'll need to handle painting the title bar yourself to achieve that.
0
 
LVL 4

Author Comment

by:Howie_Ly
Comment Utility
Hi objects.  I did suspect as much.

Seems like such a simple thing though..  have you stumbled upon any code which will help me?
0
 
LVL 15

Accepted Solution

by:
Javatm earned 50 total points
Comment Utility
>> I wish to remove or completely hide the Maximize button

     This is not possible on JFrame unless you no how to do painting method

     What you could do however is to use JInternaFrame cause Internal Frames
     is allowed to not to display the maximize button, something like this :

     // Set up the components by true or false
     JInternalFrame x = new JInternalFrame(false,true,false,true);
 
0
 
LVL 4

Author Comment

by:Howie_Ly
Comment Utility
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.

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 15

Expert Comment

by:Javatm
Comment Utility
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);
  }
 }
0
 
LVL 15

Expert Comment

by:Javatm
Comment Utility
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 );
            }
         }
       );
    }
 }
0
 
LVL 15

Expert Comment

by:Javatm
Comment Utility
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();
  }
 }
0
 
LVL 15

Expert Comment

by:Javatm
Comment Utility
>> 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.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

744 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

18 Experts available now in Live!

Get 1:1 Help Now