How to disable maximum&minimum icon on the jframe

  • Follow


Hello Everyone,

I have a problem. How can i disable maximum and minimum icon on the
jFrame?

Best Regards,

Emrah
Ankara/Turkey

0
Reply emrahayanoglu (9) 5/10/2007 9:19:40 PM

"hardemr" <emrahayanoglu@gmail.com> wrote in message 
news:1178831980.559902.309550@h2g2000hsg.googlegroups.com...
> Hello Everyone,
>
> I have a problem. How can i disable maximum and minimum icon on the
> jFrame?


this works OK using java 1.5.0_05 on win xp,
but not guaranteed to work using other versions/platforms

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Testing
{
  int count = 0;
  public void buildGUI()
  {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame f = new JFrame();
    f.setSize(400,300);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    disableMinMax(f);
    f.setVisible(true);
  }
  public void disableMinMax(Component comp)
  {
    if (comp instanceof JButton && count < 2)
    {
      comp.setEnabled(false);
      MouseListener[] listeners = comp.getMouseListeners();
      for(int x = 0, y = listeners.length; x < y; x++) comp.removeMouseListener(listeners[x]);
      count++;
    }
    if (comp instanceof Container)
    {
      Component[] comps = ((Container)comp).getComponents();
      for(int x = 0, y = comps.length; x < y; x++)
      {
        disableMinMax(comps[x]);
      }
    }
  }
  public static void main(String[] args)
  {
    SwingUtilities.invokeLater(new Runnable(){
      public void run(){
        new Testing().buildGUI();
      }
    });
  }
} 


0
Reply Michael 5/11/2007 2:09:51 AM


hardemr wrote:

>... How can i disable maximum and minimum icon on the
>jFrame?

A JFrame?  To get part of that, you can simply lock 
the size of the frame..

<sscce>
import javax.swing.JFrame;

class UnResizableFrame extends JFrame {

   public static void main(String[] args) {
      JFrame f = new JFrame("Not Resizable");
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setSize(400,200);
      f.setLocation(50,50);

      // lock the size
      f.setResizable(false);

      f.setVisible(true);
   }
}
</sscce>

..the JFrame can still be minimized to the taskbar,
in this example.

-- 
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-gui/200705/1

0
Reply Andrew 5/11/2007 6:12:26 AM

2 Replies
217 Views

(page loaded in 0.057 seconds)

Similiar Articles:




7/23/2012 9:03:57 AM


Reply: