I am fairly new to coding and I am working on a desktop application where I want to implement a dark and light mode. The problem is that I want to switch back and forth between the two, in the main class I have an instantiation of a class that represents my main view of the app if I pass and if I add an action that switches to dark/light mode it only affects the popups because the function is called after the instantiation of the main view it has the same effect if I call the function before the instantiation. I tried all sorts of solutions but I can't figure it out. If anybody has an idea thanks in advance. Here is the code.
import view.MainFrame;
public class Main {
public static void main(String[] args) {
MainFrame mainFrame = MainFrame.getInstance();
}
}
import controller.ActionManager;
import lombok.Getter;
import lombok.Setter;
import javax.swing.*;
import java.awt.*;
@Getter
@Setter
public class MainFrame extends JFrame {
private static MainFrame instance = null;
private MenuBar RuMenuBar;
private ToolBar toolBar;
private ActionManager actionManager;
private MainFrame(){ }
private void initialiseActionManager() {
actionManager = new ActionManager();
}
private void initialiseGUI() {
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension sc = tk.getScreenSize();
int height = sc.height;
int width = sc.width;
setSize(width, height);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setTitle("Dokru");
RuMenuBar = new MenuBar();
setJMenuBar(RuMenuBar);
toolBar = new ToolBar();
add(toolBar,BorderLayout.NORTH);
JPanel treePanel = new JPanel();
// JScrollPane scrollPane = new JScrollPane(treePanel); todo scroll
JPanel workspacePanel = new JPanel();
JSplitPane splitPane = new
JSplitPane(JSplitPane.HORIZONTAL_SPLIT,treePanel,workspacePanel);
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(300);
getContentPane().add(splitPane, BorderLayout.CENTER);
setLocationRelativeTo(null);
setVisible(true);
}
public static MainFrame getInstance() {
if(instance == null) {
instance = new MainFrame();
instance.initialiseActionManager();
instance.initialiseGUI();
}
return instance;
}
}