I've updated the compiler version for a basic Swing project from JDK1.8 to JDK10. This has resulted in poorer image resolution, and sizes/dimensions of JPanels now appear different. See screenshots for J8 vs J10:
Below is the entire app code:
package com.nickjwhite.test;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class App {
//UI objects
private JFrame frame;
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
new App();
}
public App() {
try {
//
//
//Initialise Parent Frame
//
//
setFrame(new JFrame());
getFrame().setSize(1200,800); // Dimensions of non-Maximised frame
getFrame().setTitle("Test App");
getFrame().setLocationRelativeTo(null); // Centre the frame
getFrame().setExtendedState(JFrame.MAXIMIZED_BOTH); // Maximise the frame on launch
getFrame().setIconImage(ImageIO.read(getClass().getClassLoader().getResourceAsStream("test.jpg")));
getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Kill process if window closed
getFrame().setVisible(true);
//
//
//Main content panel
//
//
contentPane = new JPanel(new GridBagLayout());
contentPane.setBackground(Color.decode("#2e3131"));
getFrame().setContentPane(contentPane);
//
//
//MenuPanel
//
//
JPanel menuPanel = new JPanel();
//Initialise Menu
// Title Background
//
JPanel menuTitleBg = new JPanel();
menuTitleBg.setLayout(new GridBagLayout());
menuTitleBg.setBackground(Color.decode("#d5b8ff"));
GridBagConstraints menuTitleBg_constraints = new GridBagConstraints();
menuTitleBg_constraints.fill = GridBagConstraints.BOTH;
menuTitleBg_constraints.gridx = 0;
menuTitleBg_constraints.gridy = 0;
menuTitleBg_constraints.weightx = 1;
menuTitleBg_constraints.weighty = 0;
menuPanel.add(menuTitleBg, menuTitleBg_constraints);
JLabel testImage = new JLabel();
GridBagConstraints testImage_constraints = new GridBagConstraints();
testImage_constraints.insets = new Insets(10, 10, 10, 10);
testImage_constraints.gridx = 0;
testImage_constraints.gridy = 0;
testImage.setSize(new Dimension(80,80));
testImage.setOpaque(false);
menuTitleBg.add(testImage,testImage_constraints);
try {
BufferedImage img = ImageIO.read(App.class.getClassLoader().getResourceAsStream("test.jpg"));
Image dimg = img.getScaledInstance(testImage.getWidth(), testImage.getHeight(), Image.SCALE_SMOOTH);
testImage.setIcon(new ImageIcon(dimg));
} catch (IOException e) {
e.printStackTrace();
}
menuPanel.setLayout(new GridBagLayout());
menuPanel.setBackground(Color.decode("#9b59b6"));
menuPanel.setPreferredSize(new Dimension(400, (int) (contentPane.getPreferredSize().height)));
menuPanel.setMinimumSize(new Dimension(400,10));
GridBagConstraints gbc_panel = new GridBagConstraints();
gbc_panel.fill = GridBagConstraints.BOTH;
gbc_panel.gridx = 0;
gbc_panel.gridy = 0;
gbc_panel.weightx = 0;
gbc_panel.weighty = 1;
JScrollPane menuScrollPane = new JScrollPane(menuPanel);
menuScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
menuScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
menuScrollPane.setPreferredSize(new Dimension(400, (int) (contentPane.getPreferredSize().height)));
contentPane.add(menuScrollPane , gbc_panel);
//
//
//Action Window Panel
//
//
JPanel actionWindow = new JPanel();
actionWindow.setLayout(new GridBagLayout());
actionWindow.setBackground(Color.decode("#2e3131"));
GridBagConstraints gbc_actionWindow = new GridBagConstraints();
gbc_actionWindow.anchor = GridBagConstraints.EAST;
gbc_actionWindow.fill = GridBagConstraints.BOTH;
gbc_actionWindow.gridx = 1;
gbc_actionWindow.gridy = 0;
gbc_actionWindow.weightx = 1;
gbc_actionWindow.weighty = 1;
contentPane.add(actionWindow, gbc_actionWindow);
} catch (IOException e) {
e.printStackTrace();
}
}
public JFrame getFrame() {
return frame;
}
public void setFrame(JFrame frame) {
this.frame = frame;
}
}
I need to continue compiling with JDK10 for this project, but need the GUI to reflect the JDK8 output, preferably acheiving this without having to adjust the menuPanel Preferred Size, or the testImage dimenstions.
Anyone know what's caused this?


