0

As the title suggests, when trying to set setSize(int x, int y) and x, y are below 3, it defaults to 2.

Trying setSize(1, 1) creates a 2x2 pixel frame, and setSize(0, 0) creates a 2x2 pixel frame.

I could not find anything on the internet mentioning this.

If anyone understood why this happens, please tell me!

Thank you.

https://i.stack.imgur.com/CxWJm.png

Dmitriy Popov
  • 2,150
  • 3
  • 25
  • 34
  • Who knows why this happens because it is unrealistic to create a frame that small. There is probably some kind of 1 pixel border. Post an [mre] demonstrating the problem. Also, why are you using a Frame. You should at least be using a JFrame since AWT is more outdated than Swing. What is the point of this? Maybe when using Swing you can use an undecorated JFrame.. – camickr Jun 25 '23 at 01:37
  • @camickr It is undecorated. I do not see why it is unrealistic to create a frame of such size. It is exact same as JFrame. – user22126574 Jun 25 '23 at 02:21
  • Try setting it to be undecorated first, it "could" be a OS restriction (ps - seems to work fine on MacOS) – MadProgrammer Jun 25 '23 at 03:31
  • @MadProgrammer thank you for the suggestion, will try on linux. Setting undecorated first did not change it, should not affect when it is set, as long as it's before frame.visible() – user22126574 Jun 25 '23 at 03:50
  • I always find “should not effect when it’s set” to be immediately undone by effecting it when it’s set (see any discussion on setResizable changing the window size) - it seems to be a limitation on Linux. I added a ComponentListener which printed the window size before doing anything else, might be worth seeing when the frame size changes to your undesired size – MadProgrammer Jun 25 '23 at 03:55
  • @MadProgrammer Thank you, setResizable fixed it. Did not know about this before. For some reason no posts about setResizable on stackoverflow were shown on google when searched, when had keywords. – user22126574 Jun 25 '23 at 05:43
  • *I do not see why it is unrealistic to create a frame of such size* - Again, what is the purpose? A JFrame is a "container" component, which means it is designed to contain other components. It's unrealistic in the sense that what can you do with a 1 pixel frame? How can it contain other components? Also, an [mre] should be actual code we can compile, not an image. – camickr Jun 25 '23 at 13:38
  • @camickr I got it figured out. I like to know why something happens and not give the excuse of "unrealistic". Sincerely apologize for giving the code in picture format and not code block. HOPEFULLY you can fill in the blanks and create and image object, and that is it. – user22126574 Jun 25 '23 at 15:02

0 Answers0