articles.zip
at the same level as the output directory. <helpContent> <styleSheets> <styleSheetTheme id="black" url="themeBlack.css"/> </styleSheets> </helpContent>Now the
themeBlack.css
theme will be associated with the black
id.
public class SwingThemeJavaHelp extends JFrame { private SwingHelpContentViewer viewer = null; private JComponent view = null; private JToggleButton themeButton = null; private boolean isDefaultTheme = true; ... private void createLayout() { Container cont = this.getContentPane(); cont.setLayout(new BorderLayout()); view = new JPanel(); cont.add(view, BorderLayout.CENTER); JPanel toolbar = new JPanel(); toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS)); JButton loadButton = new JButton("Load"); loadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { load(); } }); toolbar.add(Box.createHorizontalStrut(5)); toolbar.add(loadButton); toolbar.add(Box.createHorizontalStrut(5)); themeButton = new JToggleButton("Default"); themeButton.setEnabled(false); themeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { } }); toolbar.add(themeButton); cont.add(toolbar, BorderLayout.NORTH); } }We now have the following result for our application, but we still don't do anything when clicking on the toggle button:
black
theme:themeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (isDefaultTheme) { isDefaultTheme = false; themeButton.setText("Black"); viewer.setStyleSheetTheme("black"); // switch to the "black" theme } else { isDefaultTheme = true; themeButton.setText("Default"); viewer.resetStyleSheetTheme(); // reset to the default theme } } });
docJGenerator Copyright (c) 2016-2023 Herve Girod. All rights reserved.