Код: Выделить всё
import module java.desktop;
void main() {
IO.println( "Hello world" );
SwingUtilities.invokeLater( () -> {
final JFrame frame = new JFrame();
frame.setTitle( "This is a title" );
frame.setSize( 500, 500 );
frame.setLocationRelativeTo( null );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
final JPanel mainPanel = new JPanel();
mainPanel.setLayout( new BorderLayout() );
final JPanel topPanel = new JPanel();
topPanel.setLayout( new BoxLayout( topPanel, BoxLayout.X_AXIS ) );
TOP_PANEL_COMPONENTS: {
final var urlAsString = "https://b.thumbs.redditmedia.com/2rTE46grzsr-Ll3Q.png";
final JLabel redditLogo;
try {
final var url = new URI( urlAsString ).toURL();
final BufferedImage image = ImageIO.read( url );
redditLogo = new JLabel( new ImageIcon( url ) );
}
catch( final Exception exception ) {
throw new RuntimeException( "Failed to fetch image from " + urlAsString, exception );
}
topPanel.add( redditLogo );
final JButton hotButton = new JButton();
hotButton.setText( "hot" );
topPanel.add( hotButton );
}
mainPanel.add( topPanel, BorderLayout.NORTH );
frame.add( mainPanel );
frame.setVisible( true );
}
);
}
< /code>
Я запускаю это прямо из командной линии, так что ничего странного в моей IDE. Я также попробовал это с более поздними версиями Java, такими как Java 26. Обратите внимание на дополнительный мусор внизу Jbutton Как избавиться от артефактов на jbutton ? Вот увеличенный вид. Это моя проблема.
Подробнее здесь: https://stackoverflow.com/questions/797 ... oing-wrong