JFrame resizing setUndecorated(true)

I have a JFrame that it's title bar has several Images.
In Order to set these images I used setUndecorated(true)
and added the images with panels to the north area of the panel.
After this change my Frame has a fixed size.
I implementes MouseListener and MouseMotionListener handler to deal with drugging of the JFrame -how can I implement the resize of the frame?
thanks
liat

Thats why a frame has a title bar, so the mouse can click on a component and drag it somewhere. If you remove the title bar then you need to add the dragging logic to some other component. Check out this thread for a simple example:
http://forum.java.sun.com/thread.jsp?forum=57&thread=406114

Similar Messages

  • Problem with JFrame.setUndecorated(true)

    I am using a L&F that overrides the JFrame's default title bar, which requires that the following methods are called before showing my main gui.
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);after gui is shown, i have a process that pops up a new JFrame with a progress bar, with a splash screen feel (no title bar), but ever since i called the above methods, i cant get the title bar to go away.
    JFrame frame = new JFrame("go away");
    frame.setUndecorated(true);how can i have my cake and eat it too? (draw main gui with new title bar L&F, then show splash/progress without title bar)
    thanks,
    mark

    I don't play with the default LAF but have you tried something like:
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame(...)
    frame.setVisible(true);
    JFrame.setDefaultLookAndFeelDecorated(false);
    JDialog.setDefaultLookAndFeelDecorated(false);
    Show your splash screen here
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);

  • Undecorated jframe resize problem

    i created a custom jframe look by setting a jframe to undecorated and designing my own maximize/minimize/close buttons and other things to improve its appearence
    the problem is that when set to undercorated all the default resizing/move methods are gone
    i tried implementing my own resize methods, they seem to work but it flashes like crazy while resizing
    anyone have any idea how to stop all the flashing or a better way to implement this?
    the following is a small example of the problem i am having, i only implemented the north resize part so the code can be easier to read.
    thnx in advance
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.imageio.*;
    import java.io.*;
    import java.awt.image.BufferedImage;
    public class TestFrame extends JFrame implements MouseMotionListener, MouseListener
         Point sp;
         int     compStartHeight;
         int minHeight = 100;
         JPanel frameContent = new JPanel();
         public TestFrame()
              super("testing frame");
              setSize(600, 600);
              setContentPane(frameContent);
              frameContent.setBackground(Color.black);
              frameContent.setLayout(new BoxLayout(frameContent, BoxLayout.Y_AXIS));     
              setUndecorated(true);
              addMouseMotionListener(this);
              addMouseListener(this);
              JButton testButton = new JButton("TEST");
              JButton testButton2 = new JButton ("TEST2");
              frameContent.add(testButton);
              frameContent.add(Box.createVerticalGlue());
              frameContent.add(testButton2);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setVisible(true);
         public void mouseMoved(MouseEvent e)
              Point p = e.getPoint();
              if (p.y > e.getComponent().getSize().height - 5)
                   setCursor( Cursor.getPredefinedCursor( Cursor.N_RESIZE_CURSOR ));
              else
                   setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR));
         public void mouseDragged(MouseEvent e)
              Point p = e.getPoint();
              int compWidth = getSize().width;
              if (getCursor().getType() == Cursor.N_RESIZE_CURSOR)
                   int nextHeight = compStartHeight+p.y-sp.y;
                   if (nextHeight > minHeight)
                        setSize(compWidth,nextHeight);
                        validate();
              else
                   int x = getX()+p.x-sp.x;     
                   int y = getY()+p.y-sp.y;     
                   setLocation(x,y);
         public void mousePressed(MouseEvent e)
              sp = e.getPoint();
              compStartHeight = getSize().height;
         public void mouseEntered(MouseEvent e)
        public void mouseExited(MouseEvent e)
              if (sp == null)
                   setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR));
        public void mouseClicked(MouseEvent e)
        public void mouseReleased(MouseEvent e)
              sp = null;
         public static void main(String[] args)
         new TestFrame();
    }

    I doubt there is a faster / easier way to resize.
    Have you tried adding
    public boolean isDoubleBuffered()
      return true;
    }To over-ride Component.isDoubleBuffered. This should sort out your flickering problem.
    Bamkin

  • JFrame resize flicker using look&feel

    I just discovered JFrame's setDefaultLookAndFeelDecorated. Of course, it works great (refreshing to see it on vanilla windows!), but the frame flickers during mouse resizing. Every pixel the mouse moves, the frame is drawn gray then the previous frame's image is drawn over. Is there any way to stop this?
    And is there any way to do dynamic resizing? i.e. The window continuously revalidates&redraws itself while the user is resizing, and not just when the user stops resizing. At the least, is there a way to dynamically resize the border? Otherwise, a gray box (and the flicker) are the only things that shows until the user stops resizing.
    Specs: WinMe/JDK1.4.

    Run the following complete program and you should get the flicker problem when resizing it. Them dukes be still available! Tell me if you have any idea how to correct it, or how to dynamically resize the "guts" of the window. Thanks.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class JTestFrame extends JFrame {
         public static void main(String args[]) {
              new JTestFrame().show();
         private JMenuBar menuBar = new JMenuBar();
         public JTestFrame() {
              super("Java is cool");
              // Get the pane to add components to
              Container content = getContentPane();
              // Resize the frame
              Toolkit kit = getToolkit();
              Dimension wndSz = kit.getScreenSize();
              setBounds(wndSz.width/4, wndSz.height/4, wndSz.width/2, wndSz.height/2);
              // Make the frame use its look&feel for its border
              setUndecorated(true);
              getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
              // Make a menu for no other purpose than making a menu
              JMenu fileMenu = new JMenu("File");
              fileMenu.setMnemonic(KeyEvent.VK_F);
              JMenuItem fileExitMenuItem = new JMenuItem("Exit");
              fileExitMenuItem.setMnemonic(KeyEvent.VK_X);
              fileExitMenuItem.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        System.exit(0);
              fileMenu.add(fileExitMenuItem);
              menuBar.add(fileMenu);
              JTextArea text = new JTextArea();
              getContentPane().add(new JScrollPane(text), BorderLayout.CENTER);
              setJMenuBar(menuBar);
              // Set the default close operation to exit the application
              setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

  • How to resize the components in a JFrame when the JFrame Resizes?

    Hi all,
    i have some problems with my app. I have set the JFrame resizable and that works fine for the JFrame but not for the components in the JFrame.
    So my question is how can i set the components in a JFrame to resize automatically when the JFrame resizes?
    Here are the important things from my code,...if you need more, just let me know, its my first post in a forum .
    Its a JFrame with a JTabbedPane and on the Tabs are Panels with buttons and Tables.
    Thank you in advance!
    public class MainMonitor extends JFrame {
    public MainMonitor() {
              super();
              initialize();
              setVisible(true);
         private void initialize() {
              this.setSize(1145, 785);
              this.setIconImage(Toolkit.getDefaultToolkit().getImage("Images/c.gif"));
              this.setContentPane(getJContentPane());
              this.setTitle("Company Manager");
              this.setResizable(true);
              this.setLocationRelativeTo(null);
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setLayout(null);
                   jContentPane.setOpaque(true);
                   jContentPane.add(getJTabbedPane(), null);
                   jContentPane.add(getJPanel11(), null);
              return jContentPane;
         private JTabbedPane getJTabbedPane() {
              if (jTabbedPane == null) {
                   jTabbedPane = new JTabbedPane();
                   jTabbedPane.setLocation(new Point(6, 69));
                   jTabbedPane.setSize(new Dimension(1120, 684));
                   jTabbedPane.addTab("P", null, getJPanel(), null);
                   jTabbedPane.addTab("K", null, getJPanel1(), null);
                   jTabbedPane.addTab("B", null, getJPanel2(), null);
              return jTabbedPane;
         

    Giasaste wrote:
    Thanks a lot, i didnt knew that the Layout Manager is a must.It's not a must, but it is the way to allow your app to be resized nicely and makes it much easier to maintain and enhance your program. Imagine creating a complex gui then later decide that you want another radiobutton and to remove a jlabel / jtextfield pair. with layout managers a chore becomes easy.

  • Full screen displays menu even after call to setUndecorated(true)

    I am trying to implement a full screen mode for my application. It still displays the menu in Windows, and in mac if I don't set apple.laf.useScreenMenuBar to true, even if I call setUndecorated(true).
    How do I hide that menu bar? I tried removing it, but then I lose my menu hotkey to toggle out of fullscreen.
    This is my sample code:
    import java.awt.GraphicsDevice;
    import java.awt.GraphicsEnvironment;
    import java.awt.Rectangle;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.KeyStroke;
    public class FullScreen extends JFrame {
        static JFrame window;
        public static void main(String argv[]) {
            if(System.getProperty("os.name").startsWith("Mac OS X"))
                System.setProperty("apple.laf.useScreenMenuBar", "true");
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    window = new FullScreen();
                    window.setVisible(true);
        private GraphicsDevice graphicsDevice;
        private boolean fullScreenMode;
        private Rectangle previousSize;
        private JMenuBar menus;
        private FullScreen(){
            JButton but= new JButton("switch");
            menus= new JMenuBar();
            JMenu menu = new JMenu("View");
            JMenuItem item = new JMenuItem("full screen");
            item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK));
            item.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e) {
                    toggleFullScreen();
            this.setJMenuBar(menus);
            menus.add(menu);
            menu.add(item);
            but.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e) {
                    toggleFullScreen();
            this.add(but);
            //prep for fullscreen mode
            GraphicsEnvironment ge =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
            graphicsDevice = ge.getDefaultScreenDevice();
            pack();
        public void toggleFullScreen() {
            if (fullScreenMode){
                this.dispose();
                this.setUndecorated(false);
                this.setResizable(true);
                this.setBounds(previousSize);
                graphicsDevice.setFullScreenWindow(null);
                this.setVisible(true);
            }else{
                if(graphicsDevice.isFullScreenSupported()){
                    this.dispose();
                    previousSize=this.getBounds();
                    this.setUndecorated(true);
                    this.setResizable(false);
                    graphicsDevice.setFullScreenWindow(this);
    //                drawingPanel.setPreferredSize(new java.awt.Dimension( this.getBounds().width, this.getBounds().height));
                    this.setVisible(true);
            fullScreenMode = !fullScreenMode;
    }Edited by: jstoner on Jun 14, 2009 10:36 PM

    if (fullScreenMode){
        menus.setPreferredSize(null);
        ...  //exit fullscreen mode
    }else {
        menus.setPreferredSize(new java.awt.Dimension());
        ... //enter fullscreen mode
    }

  • During the JFrame resize, unable to call mylogic.How to know JFrame rezing?

    {font:Arial}{size:10pt}Hi
    In my project i came across an issue. In that I had a JFrame (with FlowLayout) added with 24 JButtons (Its appearence will be similar as JToolbar). On this JFrame i called pack(). When i try to resize the JFrame, its componentResize() listener will not be called every time, instead it is calling only when its resizing complete.
    I am looking for a solution, that will rearrange JButtons (as specified Column/Row wise) during the JFrame resize. Can any body help me why componentResize() is not calling, during the resize. Tell me all alternate solutions. Pls help me.
    Waiting for your reply
    {size}{font}

    Can any body help me why componentResize() is not calling, during the resizeBecause its not very efficient to layout the frame every time you move the mouse 1 pixel. So by default this behaviour is turned off. I think you can turn in on by adding the following at the start of your program:
    Toolkit.getDefaultToolkit().setDynamicLayout(true);

  • Resizing Image when JFrame resized?

    I have a JFrame with a JPanel added to the contentPane (BorderLayout.CENTER). In the JPanel is a JLabel (BorderLayout.CENTER) with an ImageIcon set to it. The image is a subimage of a larger image whose width is scaled to fit the current JLabel width (which is dictated by the JPanel width and finally dictated by the JFrame width).
    When the user resizes the JFrame, the image of the ImageIcon should be replaced with a new image which has been scaled to fit the new width and that reflects the new portion of the larger source image that is visible.
    The JFrame already has a ComponentListener added for retaining the current JFrame size and screen position, but calling my resizeDisplay() method from componentResized() does not seem to have the updated JLabel size. I have added a ComponentListener to the JLabel and called my resizeDisplay() method from componentResized() but it does not seem to have the updated JLabel size either.
    How can my application properly react to JFrame resizes so that the method is retrieving the new size values?
    Thanks,
    Robert Templeton

    Its always easier to solve a problem when sample code (not a complete program) is posted with the question.
    Maybe I don't understand the question, but when I run the following code the output reflects the size of the label after it has been resized. I'm using JDK1.3 on Window 98.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class TestLabel extends JFrame
         public TestLabel()
              JPanel panel = new JPanel();
              setContentPane( panel );
              panel.setPreferredSize( new Dimension( 200, 200 ) );
              panel.setLayout(new BorderLayout() );
              final JLabel myLabel = new JLabel( new ImageIcon("dukeWaveRed.gif"), JLabel.CENTER );
              panel.add( myLabel );
              myLabel.addComponentListener( new ComponentAdapter()
                   public void componentResized(ComponentEvent e)
                        System.out.println( myLabel.getSize() );
         public static void main(String[] args)
              TestLabel frame = new TestLabel();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
    }

  • Implementing JFrame Resizing Rules?

    Recently I've needed to enforce rules on a JFrame's dimensions (for example: preserving an aspect ratio).
    The obvious solution is to call setSize() from ComponentListener's componentResize() method. This is functional, but looking at the Java source, it's pretty inelegant. It actually starts a setSize() -> componentResized() -> setSize() loop that only terminates when setSize() is called with dimensions matching the current dimensions (see Component.reshape()). Also, its visually ugly because when maximized you can see the window snap back to the "fixed" size.
    It would seem that a more elegant way to add this functionality would be to have a method like "public Dimension checkDimensions(Dimension)" available for overriding.
    Does something like this already exist that I've missed?
    I've tried following the source, but I can't find the place where JFrame resizing is handled.

    The optimal solution would be to use a Look&Feel which doesn't have to use the OS window decorations, so the resize events are only generated in Java (not optimal in the fact that you don't get to have the OS frame decorations of course). Then you should be able to add your own RootPaneUI which simple doesn't allow resizing beyond a maximum size or auto resizing respecting an aspect ratio.
    See JFrame#isDefaultLookAndFeelDecorated and (for example) MetalRootPaneUI#MouseInputHandler. Perhaps there are thrid party look and feel where you can more easily replace a similar handler.

  • JFrame resize dynamically in response to content pane size changes

    Hi -
    I have a JFrame that uses CardLayout. The CardLayout panel content is of varied dimensions. it means the JComponents added to CardPanel will change size dynamically.
    Is it possible to have the JFrame resize dynamically in response to the content of the CardLayout panel changing?

    camickr wrote:
    No, the preferred size of a panel using a CardLayout is the preferred size of the largest component added to it.
    As a user I think it would be terrible to have the frame resize every time a turn a page to go to the next card. I have never seen this any any application.
    If you really need this functionality, then manage the panels yourself. Remove the existing Component before adding the next component and then do a frame.pack().My Application will be a JFrame.
    inside this JFrame i want to have three JPanels. according to some events and logic my GUI should switch to a given JPanel from those three panels. as i said the Jpanels sizes will change size on runtime depending on a automatic swing JPanel generation and i will have to add the new generated JPanel to parent JFrame with its new size
    any Ideas how to achive this ?

  • JFrame resize restriction

    Does anyone know of a way to restrict resizing of a JFrame to only one direction? (i.e. allow the JFrame to be resizable horizontally, but not vertically?) Also, the JFrame is NOT an internal frame.
    Thanks!

    quick demo:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Example {
        public static void main(String[] args) {
            JFrame f = new JFrame();
            f.addComponentListener(new ComponentAdapter(){
                public void componentResized(ComponentEvent e){
                    Dimension sz = e.getComponent().getSize();
                    if (sz.width != 400)
                        e.getComponent().setSize(400,sz.height);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(400,400);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • Problem with JFrame resizing at runtime

    Hi All,
    I have a problem with resizing the JFrame at runtime. Even if i resize the JPanel. It is not affection on all the components over the frame. How can i solve that I am using AbsoluteLayout(jre1.6) and here i am going to provide you code snippet. My requirement is to resizt the form. If form is small in size then all the component should also be according tothe size of the form.
    public void initComponents(int size) {
    if(size >= 50) {
    x_co_or = 300;
    y_co_or = 300;
    } else if(size < 50) {
    x_co_or = 200;
    y_co_or = 200;
    jPanel1 = new javax.swing.JPanel();
    jButton1 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
    jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
    jButton1.setText("jButton1");
    jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 40, 110, 40));
    getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, x_co_or, y_co_or));
    pack();
    Can anybody suggest any idea/solution.
    Any idea/solution are most welcome.
    Regards,
    Pradeep Dubey

    How can i solve that I am using AbsoluteLayout(jre1.6)
    and here i am going to provide you code snippet.no need for the snippet, you're using absolute positioning, which means you're responsible for location and size on every single change.
    start coding now, take about a week, or you could use a layout manager, take maybe, 5 minutes

  • JFrame resizing

    Hi,
    I have a JFrame, it displays on the right upper corner the icons minimize, maximize and exit.
    Minimize and Exit icons are working fine.
    I have the problem with the maximize button.
    The application I am writing allows to resize the JFrame. Thats fine!
    If I run the application, it has an initial size w=800, h=600
    If I click the maximize button, the JFrame fits to the window maximal size.
    But if I click the maximize button again, I want to have the initial size. This does not work.
    It keeps the maximal size.
    How can I switch
    - between maximal size and "initial" size
    or
    - between maximal size and last set size (so the size before Jframe was maximized)
    if I click the maximize button.
    Thanks
    A.

    Hi,
    I found the issue and fixed it.
    The issue is the following code.
    If I run the application, I call this function, it works fine.
    What it does is, it just horizontal center the window.
      public static void centerWindow(Window window) {
          Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
          int x = (int)((screen.width - window.getSize().width) / 2);
          int y = 0;
          window.setLocation(x, y);
      }If I run this function later on again after resizing the window, it causes the issue.
    So if I resize the window, I don't call this function anymore.
    Thanks
    A.

  • JFrame resizing question

    When i resize a JFrame the components it hold remain unchanged until I stop resizing the frame. Then the components conform to the frame size. Is there a way to have the components resize dynamically?

    Thank for the answer, that's exactly what I nedded!

  • JFrame resizing problem......

    Hi All,
    can anyone guide me how to stop resizing or dragging the JFrame.
    my frame should not be movable or resizable by the user.
    Urgent!!
    Regards
    sd

    Have you tried frameObj.setResizable(false)?
    Phani

Maybe you are looking for