Size « JFrame « Java Swing Q&A





1. How can I change the size of frame?    stackoverflow.com

I have a frame which has a menu item for choosing the font and its size, when the user choose her/his font size, all the text of buttons, panels, which are ...

2. NetBeans (Java Swing): Set window size    stackoverflow.com

This is driving me crazy. When I set an appropriate size for my window in design-mode it just ignores this size and uses something else when I compile and run. Even ...

3. Usable frame size and Windows Manager frame size    stackoverflow.com

I'm setting a JFrame size with myFrame.setSize(Xsize,Ysize), but it gives me a problem : this doesn't define the usable space in the frame but the whole frame's size (it include the ...

4. Why Java jFrame setResizable() is failling to act?    stackoverflow.com

This code is automatically generated by Netbean 6.8 GUI builder. The default application was not contained in a jFrame! It was in jPanel only which I didn't know how to make ...

5. How come JFrame window size in Java does not produce the size of window specified?    stackoverflow.com

I am just messing around trying to make a game right now, but I have had this problem before too. When I specify a specific window size (1024 x 768 ...

6. Swing: set JFrame content area size    stackoverflow.com

I'm trying to make a JFrame with a usable content area of exactly 500x500. If I do this...

public MyFrame() {
    super("Hello, world!");
    setSize(500,500);
}
... I get ...

7. Why aren't my coordinates matching my JFrame size?    stackoverflow.com

I want to do some drawing in a JPanel but the enclosing JFrame size doesn't seem to match where I've asked the coordinates to be drawn. In my example code, the JFrame ...

8. Is there any way in Java to enforce a minimum window size?    stackoverflow.com

Is there any way in Java to enforce a minimum window size? The last article I can find is from 1999, and has some complicated code to mimic the behaviour... http://www.javaworld.com/javaworld/javaqa/1999-10/03-qa-window.html Surely ...

9. Setting minimum size limit for a window in java swing    stackoverflow.com

I have a JFrame which has 3 JPanels in GridBagLayout.. Now, when I minimize a windows, after a certain limit, the third JPanel tends to disappear. I tried setting minimizing size of JFrame ...





10. Setting the size of a ContentPane (inside of a JFrame)    stackoverflow.com

I want to set the size of a JFrame such that the contentPane is the desired size. JFrame.setSize() doesn't take the window decorations into account, so the contentPane is slightly ...

11. How do I get the real usable resolution    stackoverflow.com

with Toolkit.getDefaultToolkit().getScreenSize() i do geht the screen size. But usually this isn't the available size i have for my own program, because on the mac there is a on top an menubar and a ...

12. setting the size of a JFrame    stackoverflow.com

I want to be able to resize the JFrame when I click a button, so here's the code:

public void mouseClicked(MouseEvent arg0) {
        try {

 ...

13. Frame size of Java app on HTC HD2 with Windows Mobile 6.5    stackoverflow.com

I have a Java app that had been written originally to run on a HTC P6500 Windows Mobile device using a JVM from Esmertec (or whatever the company is now called). ...

14. Opening a JFrame in the last closed size    stackoverflow.com

I have a JFrame in my application. I would like to open the JFrame in the same size as it was when last closed. So I have added a Component Listener, ...

15. JFrame size decreasing    stackoverflow.com

I need your help in java 1.4. How can I prohibit JFrame decreasing. In java 5 or 6 I just:

new JFrame("TEST").setMinimumSize(...);
But how in java 1.4? That code does not work!

16. Swing Application Framework does not save program's session (window postition, size etc.) in Linux    stackoverflow.com

I'm developing a tiny app in Java using Swing and Swing Application Framework (JSR 296). It should work under Windows and Linux. In Windows XP session (window postition, size etc.) is saved, but ...





17. Java Swing set "actual" Frame size (inside)    stackoverflow.com

I have a JFrame which contains just one JPanel. I have tried setting the Panel's size and packing the frame, but that has no effect. If I set the JFrame's size, it will ...

18. Circles disappear when maximizing, minimizing or resizing my JFrame.    stackoverflow.com

This is my code:

    JFrame frame = new JFrame();
    frame.setSize(400, 400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JPanel panel1 = new JPanel(){
  ...

19. JFrame Default size on ubuntu    stackoverflow.com

I use ubuntu 10.04, but have discovered this on other ubuntu distributions as well. When I start the first JFrame of an application, it won't start in its default size (specified by ...

20. Java window contents resize, but not beyond a minimum size    stackoverflow.com

I have a Java apps I've written using NetBeans (yes, I've read plenty of complaints here about NetBeans). When I resize the window, the contents resize with the window, until ...

21. Java JFrame size and centre    stackoverflow.com

I'm working on a uni project which is to create a dice face using 2d graphics shapes. I have got that all done but I have a problem: I want my ...

22. How do you find out the REAL size of a JFrame?    stackoverflow.com

I have a JFrame which is maximized (frame.setExtendedState(JFrame.MAXIMIZED_BOTH)). I want to find out the size it is now extended to, but frame.getSize() returns a size of (0, 0).

23. How to get maximized size of frame?    stackoverflow.com

I set maximized frame: setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH); Now how I can get this size, because when I call getSize() or getPreferredSize it returns 0 0?

24. How to set specific window (frame) size in java swing?    stackoverflow.com

My code does not work:

    JFrame frame = new JFrame("mull");

    mull panel = new mull();

    // add panel to the center of ...

25. How to check current window size in java swing?    stackoverflow.com

For instance, the size of the window changed (user resized it), how to get current window size?

26. JFrame strange sizing    forums.netbeans.org

hello! I've put together a Jframe that looks fine in Design mode, but when I click preview, the frame goes much larger with a big amount of dead space to the ...

27. Multi Window GUI and Frame Size    forums.netbeans.org

1) How do I a) set the size of the window and b) disable maximizing the window. I know I can do a .setSize() on the panel that my objects are ...

28. JFrame sizing dilemna    forums.netbeans.org

I am very new to Netbeans and developing GUIs for Java. So if my questions are far too basic I apologize in advance. I am now trying to create a full blackjack game where up to 3 or 4 players can sit at the table and play. I am confused as to what SPECIFIC size I should set my JFRAME at ...

29. How to set maximum size of the JFrame    coderanch.com

30. JFrame not sizing    coderanch.com

Hi ! I am having trouble with a JFrame. I have added 2 panels containing some textfields onto the frame. I have not set the size of the panels. I have not set the size for the frame but have specified pack() in the frame constructor.My understanding is that it should fit the components i.e the textfields When I run the ...

31. Frame SIze    coderanch.com

Hi ppl, if we create some frame then by double clicking it usually expand it to default screen size. what if i want to restrict it ? there is a method of setRisizable but after doing setResizable false of specific frame , it doesn't allow it to resze but still it can expand it to full screen size waiting for reply ...

32. window size    coderanch.com

The main window and most of the dialogs of my program are resizable. Is there any way to limit the minimum size since the windows start to get very ugly when reduced too far. I have tried setting the minimum and preferred sizes on all of the containers, but they seem to be ignored. Is this tied to the fact that ...

34. Setting JFrame size    coderanch.com

Hi Alagapan, IMO, you can't do anything about it. My reasoning: 1. Taskbar is OS specific (exists on Windows not on Mac or Unix) 2. Taskbar can be placed anywhere on screen (even off screen! Made visible only with mouse location near it!) 3. Java is written to be independent of OS so I don't believe it has any classes that ...

35. Size of window ???    coderanch.com

36. Control the minimum size of a JFrame    coderanch.com

Sorry about posting what's probably a trivial question to you SWING Gurus, but ... I have a resizable JFrame as the outermost container of my SWING application. How can I restrict the minimum size to which it can be set? While I'm here, some slightly harder, related questions: - Can this be automatically calculated from the minimum sizes of the contents ...

37. Setting minimum size for a java.awt.Frame    coderanch.com

i dont think u can. you can either make it non resizable alltogether, or u can override the getminimumSize() method to set the minum size of the frame. BUT if u let the users resize it they can do whatever they want. one more option i can think of but havent tried is to use the ComponentListener and override the method ...

38. restricting JFrame resize to some minimum size    coderanch.com

This may not be great... but you can listen for resizes below the minimum size and pop the JFrame back to it's minimum size... import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MinimumFrame extends JFrame { public MinimumFrame( String title ) { super( title ); enableEvents( AWTEvent.COMPONENT_EVENT_MASK ); setSize( getMinimumSize() ); } public Dimension getMinimumSize() { return new Dimension( 300, 300 ...

39. Window Size    coderanch.com

Can someone help me out? I am getting frustrated... I would like to start a new Swing app, with a predefined width and height, centered in the screen. I would like this window to always stay the same size, regardless of the contents. I have tried the following: Toolkit toolkit = Toolkit.getDefaultToolkit(); // Get the size of the host platforms screen ...

40. problem with frame size    coderanch.com

hi, i m not to sure, but may be the code is useful to you. /** * Resize the image. *@param original path of image file to be resized. *@param wid width of the resized image. *@param het height of the resized image. *@return Image */ public static Image resize(String original, int wid, int het) { Image resizedImage = null; try ...

41. Size of frame problem /XP    coderanch.com

43. Enforcing Minimum Size in Frames    coderanch.com

Well this is pretty simple, I'm wondering how I ensure that my JFrame or JInternalFrame has a certain minimum size. I'm using GridBagLayout and at a certain point the components inside it, labels, text fields, etc. stop scaling and instead start moving becoming a jumbled overlapping mess of components. Basically, rather than trying to make it so that these components have ...

44. size of the frame    coderanch.com

hey usually when we run the gui frame has the size that we specified when we maximize it, it grows up to full size of screen. here wht i want is when we run the the programme the frame should be the size of the screen(ofcourse differenct monitors have different screen size) and then i should be able to minimize for ...

46. Size of undecorated area of JFrame    coderanch.com

47. Window fixed size problem    coderanch.com

Hi, I have to make a screen of fixed size. Means if the user drags the frame then also it should come back to its normal size. I am able to make the frame of fixed size by doing public void componentResized(ComponentEvent e) { if( (this.getHeight() < this.DIALOG_HEIGHT) || (this.getWidth() < this.DIALOG_WIDTH) || (this.getHeight() > this.DIALOG_HEIGHT) || (this.getWidth() > this.DIALOG_WIDTH) ) ...

48. Window Size    coderanch.com

> My problem is the last panel is not visible when i run the application. which one? the last of the 5 added to the contentPane, or the last of this one > The first jpanel is a nested panel with 2 borderlayout panels each with 2 flowlayout panels. when using gridbaglayout, you are much better off supplying a working sample ...

49. Seeting the size of JFrame    coderanch.com

50. Minimum size for JFrame    coderanch.com

51. Prevent JFrame from minimizing    coderanch.com

52. How to set the Maximum size of Application Window when Loaded?    coderanch.com

I am doing a Project I need to see the Application window with Full Screen size GUI. I have tried with method like setExtendedState(), SetMaximumSize(). setMinimumSize() and setMaximizedBounds(). I am using NetBeans as GUI Builder. I am not getting the requirement when the Form is executed. How can I fix this? Thanks and Regards Prithiraj Sen Gupta [ January 21, 2008: ...

54. Annoying Window Size Problem    coderanch.com

import java.awt.Frame; public class Application extends Frame { public Application(int rows, int cols, int mines) { super("Minesweeper"); setVisible(true); add(new Board(rows,cols)); addWindowListener(new FrameListener()); setSize( rows*19, cols*19 ); } } Hello everyone, I have this really irritating problem. I can't get the frame the size i want it to be. If i run this I get the right size but the content isnt ...

55. Sizing a JFrame during printAll()    coderanch.com

Hi, Once again, I have been pulling my hair out searching the web for the solution to this, all to no avail. So I ask youguys, how do I resize my JFrame during printing so that it prints the whole JFrame? I am asking because I have a JFrame that when printed using graphics2d and a printerJob(), prints only the top ...

56. JFrame re-sizing, what methods are called?    coderanch.com

I've got a bit of a problem, I'm using a transparent JTable, when I change the data on it I can still see the old value that was in the cell before. The only way I can get rid of it (so far) is to resize the frame, so what methods are called when a frame resizes? I've tried invalidate(), validate() ...

58. How can I set the frame's size flexible to show it's title(variable length) in full?    java-forums.org

private static void fitFrameTitle(JFrame frame) { FontUIResource font = (FontUIResource) UIManager.get("InternalFrame.titleFont"); if (font != null) { int prefferedWidth = frame.getWidth(); int prefferedHeight = frame.getHeight(); FontMetrics fm = frame.getFontMetrics(font); Rectangle2D bnds = fm.getStringBounds(frame.getTitle(), frame.getGraphics()); prefferedWidth = (int) bnds.getWidth() + 50;//50 is space for the maximise and minimise buttons might need to increase this Dimension dimension = new Dimension(prefferedWidth, prefferedHeight); frame.setPreferredSize(dimension); frame.setMinimumSize(dimension); frame.pack(); ...

59. Setting frame size to the size of an image    java-forums.org

import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; import javax.swing.JFrame; import javax.swing.JPanel; public class Test { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { MyFrame frame = new MyFrame(); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setResizable(false); } }); } } class MyFrame extends JFrame { private JPanel imagePanel; BufferedImage image; Dimension dim; public ...

60. GUI based java program where size of the frame increases    java-forums.org

import java.applet.*; import java.awt.*; import java.awt.event.*; class MyFrame1 extends Frame { MyFrame1() { setTitle("this is the Frame...."); setBackground(Color.GREEN); setSize(200,200); setVisible(true); setFont(new Font("Dialog",Font.BOLD,10)); MyMouseAdapter adapter=new MyMouseAdapter(this); addMouseListener(adapter); //addWindowListener(new MyWindowAdapter(this)); } public void paint(Graphics g) { g.drawString("Click HERE",30,60); } } class MouseClick { public static void main(String args[]) { MyFrame1 mf=new MyFrame1(); } } class MyMouseAdapter extends MouseAdapter { MyFrame1 mf1; int x=200;int ...

61. frame changes size even tho i told it not to :D    java-forums.org

Hello. I have a frame which contains a container. that container is set to use the borderlayout layout. this container has 4 panel in it each with it's own components. i havent set any size related restrictions on the frame or what's in it. one panel has a button. when i press it, an event takes place. the result forces the ...

62. JFrame Size    java-forums.org

When one sets the size of a JFrame, for example JFrame frame = new JFrame(); frame.setSize( 400, 600 ); what is the actual size of the associated content pane? In the above example, what is 400 px by 600 px? If I set a box layout for the content pane, and add components with a sum of heights equal to 600 ...

63. Listener for JFrame size change    java-forums.org

Is there a listener that I can use that will listen for any size changes in the window/JFrame? If the user resizes manually or the user maximizes/restores then I need to be able to get the new size, compare it to the old one and then move objects depending on the change. Also, is there a way to know if a ...

64. Image size in a JFrame    java-forums.org

The easy/naive way to scale the image to fill the component, viz, your contentPane, is to scale the width and height of the image to the respective width and height of the component. In java: Java Code: double xScale = (double)componentWidth/imageWidth; double yScale = (double)componentHeight/imageHeight; int width = (int)(xScale*imageWidth); int height = (int)(yScale*imageHeight); This will distort the image when the component ...

65. Ensure proper size for JFrame    forums.oracle.com

Background info: My JFrame's contentPane uses BorderLayout, and the center component is a custom component which I have created to extend JLabel, and I programmed it to have its own paint method and calculate its dimensions, the latter of which happens the moment it is created, and can be fetched with any of getSize, getPreferredSize, getMinimumSize, getMaxiumumSize, getWidth, and getHeight, all ...

66. How Do You Set a JFrame's Maximum Size?    forums.oracle.com

Can someone show me a quick example? The JFrame can be empty, I just want to know how to set it's maximum size. I tried using setMaximumSize() and it doesn't work for some reason but setMinimumSize() works fine. I tried it using a BoxLayout and even using null as a layout manager and can't get it to work. I heard that ...

67. Setting the image size within a JFrame!    forums.oracle.com

Read it.Got a lot of info from that.But the trouble with mine is that i am linking the image to the JLabel and thats why i am unable to set its size because the image will be added to the JPanel when i add the JLabel to it?If i was directly printing the image i would have rather used Graphics.drawImage( ) ...

68. Cannot set the initial size of nested JFrame in NetBeans 5.5.    forums.oracle.com

For some background; I'm trying to design a small configurable, multi-market clock for Traders of foreign currency. Several international market times will be displayed and each will change color as that market opens and closes. The user will be able to select specific foreign markets and configure several options such as color and size. I was trying to use a JFrame ...

69. setting the jframe size    forums.oracle.com

1) Don't set the size of the JFrame. Instead set the size of its contentPane (via getContentPane()). 2) Avoid setting size via setSize(...). Instead it's usually best to set the preferred size via setPreferredSize(...) and calling pack() on the JFrame. 3) Also good practice is to use the proper layout managers so that your buttons are placed automatically, and avoid use ...

70. On minimizing application in Swings,components of frame become unordered    forums.oracle.com

Make sure you are using the layouts correctly etc. It sometimes help for example in a grid layout to create a blank panel with nothing in it for layout purposes only. Once layout has been configured correctly is should not change. Have a look and make sure u understand how layout works and how things are added and in what order. ...

71. JFrame maximum size    forums.oracle.com

Hi! I'm using a JFrame in a game I'm developing, and this should be resizeable within some bounds. This works fine for the minimum size, the user is unable to even try to resize the frame smaller than what I've set as the minimum size. But it seems like maximum size is a different issue - I can't find a way ...

72. setting jframe size    forums.oracle.com

73. Why I can't get the JFrame size?    forums.oracle.com