I am using this code to set up a look and feel on a program:
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName());
I am only using the system look and feel on a JPanel (inside a JFrame) that i show during the runtime of the program. The first time i show the JPanel, the L&F is wrong (looks like it is for an older version of windows or something, not the same as i used before, on the other components). I hide the JPanel then open it agin, the L&F is now correct.
Sadly i wasn't able to produce a reproducaple example but the problem persists in the original program.
It consists of multiple classes, and has an object orientedly written UI, this is the code responsible for the problematic JPanel:
package almanah;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class SeriesProperties extends JPanel {
JButton button_close = new JButton();
JPanel container = new JPanel();
JScrollPane scPane = new JScrollPane(container);
public SeriesProperties(ItemLib lib) {
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
Logger.getLogger(SeriesProperties.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(SeriesProperties.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(SeriesProperties.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(SeriesProperties.class.getName()).log(Level.SEVERE, null, ex);
}
this.setLayout(new BorderLayout());
this.add(button_close, BorderLayout.EAST);
button_close.addActionListener((e) -> {
Almanah.frame.swapToTiles();
});
scPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
this.add(scPane, BorderLayout.CENTER);
//container
container.setBackground(Color.red);
container.setLayout(new WrapLayout());
for (int i = 0; i < 100; i++) {
JPanel panel=new JPanel();
panel.setPreferredSize(new Dimension(100, 100));
container.add(panel);
}
this.updateUI();
}
}