I have a
Код: Выделить всё
JFrameКод: Выделить всё
pack()I also call a method on my
Код: Выделить всё
JFrameКод: Выделить всё
setLocationByPlatform(true)However, when calling these 2 together, they end up with part of my frame being off-screen.
Now, there are a million-and-1 ways to work around this. I could full screen my application, which is most likely the real solution here. I could deactivate either or both options. I could set my size and location explicitly. And there's more solutions.
But is there any way to call both
Код: Выделить всё
pack()Код: Выделить всё
setLocationByPlatform(true)And to be clear, I am A-OK with the actual content on my frame being cut off because the frame is too small. By all means, if the frame is too small to hold all of the content, that is a different problem that I already have solutions that I will later apply. But for now, to demonstrate the point, I am A-OK with an answer that allows content to be cutoff the window, but the full window is fully on-screen.
And not that this needs a code example, but here is one.
Код: Выделить всё
import javax.swing.*;
public class SOQ_20231003
{
public static void main(final String[] args)
{
SwingUtilities.invokeLater(SOQ_20231003::new);
}
public SOQ_20231003()
{
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
final JPanel panel = new JPanel();
for (int i = 0; i < 100; i++)
{
final JButton button = new JButton();
final String text =
"""
Totam qui nihil qui possimus architecto. Quo quia voluptatem possimus. Aliquid praesentium ab assumenda nisi eligendi eum dolore sed. Sint dolorem eaque est vitae ipsam architecto. Consectetur consequatur ipsum assumenda nostrum debitis ab a nobis. Dignissimos nobis rem aut nihil mollitia rerum. Porro quis neque eos. Dolorum eum sit aperiam cumque velit nulla quidem qui. Velit facilis maiores rerum mollitia. Tempore dolor consequatur quis. Similique minima animi et et repellat quam. Hic dolore voluptatem tempora est et dolor atque dolores. Odio est repellendus fugiat neque ut quas sunt quia. Sunt ea ab qui. Placeat pariatur dolores quis earum exercitationem. Nulla aut id nulla pariatur. Officia architecto sunt ipsum. Quo voluptatibus aut qui voluptates velit accusamus fuga. Beatae et ullam adipisci. Quo ducimus et in quam soluta officia ducimus. Placeat molestiae qui quia ut. Sint dolorem porro amet minus. Labore expedita dolorem omnis eveniet et quis.
"""
;
button.setText(text);
panel.add(button);
}
frame.add(panel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true); //image is cut-off on the right hand side of the screen!
}
}
Код: Выделить всё
pack()Код: Выделить всё
setLocationByPlatform(true)Код: Выделить всё
resizeToAvoidClippingScreenИсточник: https://stackoverflow.com/questions/772 ... lling-pack
Мобильная версия