Solved

Hide/remove maximize button on JFrame.

Posted on 2003-11-18
8
7,075 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
ID: 9776247
Think you'll need to handle painting the title bar yourself to achieve that.
0
 
LVL 4

Author Comment

by:Howie_Ly
ID: 9776277
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
ID: 9776278
>> 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 4

Author Comment

by:Howie_Ly
ID: 9776426
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
 
LVL 15

Expert Comment

by:Javatm
ID: 9776551
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
ID: 9776575
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
ID: 9776622
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
ID: 9776660
>> 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

785 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