我在屏幕上看不到红色方块.我将框架从不可调整大小切换为可调整大小,如果将窗口放大,则红点在那里.框架大小是否与应用程序的窗口大小相同?如何使应用程序的窗口恰好是500x500?解决方案框架是整个窗口的大小,包括操作系统所需的标题栏.在JFrame的JPanel中绘制内容时,如果JPanel从标题栏的下方开始,则(0,0)坐标位于左上角.听起来您的标题栏比10像素高,所以490作为y分量实际上不在窗口内,因为JPanel的可见高度是windowHeight - titleBarHeight.I am making a JFrame with the size of 500x500 pixels.I make a blue background and add a red square in the right-bottom corner from (490,490) to (500,500).Image:I don't see the red square on the screen.I switched the frame from not resizable to resizable and if I make the window larger the red dot is there.Is the frame size the same as application's window size?How can I make the application's window to be the exactly 500x500? 解决方案 The frame is the size of the entire window, including the title bar required by the OS. When drawing things in the JPanel in the JFrame, the (0, 0) coordinate is in the top left corner if the JPanel, which begins just below the title bar. It sounds like your title bar is taller than 10 pixels, so 490 as a y component is actually off the window, since the visible height of the JPanel is windowHeight - titleBarHeight. 这篇关于Java JFrame setSize无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-29 16:11