Beruflich Dokumente
Kultur Dokumente
The following short code fragment shows you the way to use themes for customizin
g the appearance of the choosen look and feel. Espacially how to set the logo in
the lower left corner of popup menus.
For a complete list of the properties see : theme properties
/*
* Copyright 2005 MH-Software-Entwicklung. All rights reserved.
* Use is subject to license terms.
*/
package com.jtattoo.demo.app;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.jtattoo.plaf.smart.*;
public class ThemesDemo extends JFrame {
public static ThemesDemo app = null;
public JPopupMenu popup = null;
public ThemesDemo() {
super("Themes-Demo-Application");
// setup menu
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
menu.setMnemonic("F");
JMenuItem menuItem = new JMenuItem("New");
menu.add(menuItem);
menuItem = new JMenuItem("Open");
menu.add(menuItem);
menuItem = new JMenuItem("Save");
menu.add(menuItem);
menuItem = new JMenuItem("Save as");
menu.add(menuItem);
menu.addSeparator();
menuItem = new JMenuItem("Exit");
menuItem.setMnemonic("x");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, KeyEvent.
ALT_MASK));
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.exit(0);
}
});
menu.add(menuItem);
menuBar.add(menu);
setJMenuBar(menuBar);
// setup the widgets
JPanel contentPanel = new JPanel(new BorderLayout());
contentPanel.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));
JTree tree = new JTree();
tree.expandRow(3);
tree.expandRow(2);
tree.expandRow(1);
JScrollPane westPanel = new JScrollPane(tree);
JEditorPane editor = new JEditorPane("text/plain", "Hello World");
JScrollPane eastPanel = new JScrollPane(editor);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true,
westPanel,eastPanel);
splitPane.setDividerLocation(148);
contentPanel.add(splitPane, BorderLayout.CENTER);
setContentPane(contentPanel);
// setup the popup menu
popup = new JPopupMenu();
menuItem = new JMenuItem("undo");
popup.add(menuItem);
menuItem = new JMenuItem("redo");
popup.add(menuItem);
popup.addSeparator();
menuItem = new JMenuItem("cut");
popup.add(menuItem);
menuItem = new JMenuItem("copy");
popup.add(menuItem);
menuItem = new JMenuItem("paste");
popup.add(menuItem);
menuItem = new JMenuItem("delete");
popup.add(menuItem);
// add the popup to the editor pane
editor.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
maybeShowPopup(e);
}
public void mouseReleased(MouseEvent e) {
maybeShowPopup(e);
}
private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
});
------------------------------------------------------------------
How to use predefined themes.
There are only two steps to select a predefined theme and set the look and feel
you want:
com.jtattoo.plaf.acryl.AcrylLookAndFeel.setTheme("Green", "INSERT YOUR LICEN
SE KEY HERE", "my company");
UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
All look and feel's within the JTattoo package do have a static method named set
Theme. The first parameter is the name of the theme you want to select. The seco
nd parameter is the license key (you will get one if you purchase a license) and
the last parameter is the string you want to show in the lower left corner of p
opup-menus. If you don't have a license key, this will work as well, with the re
striction that you can't set the string in popup-menus.
For a complete list of the predefined themes see : Predefined themes
Here's a simple demo application to illustrate the setTheme method:
/*
* Copyright 2006 MH-Software-Entwicklung. All rights reserved.
* Use is subject to license terms.
*/
package com.jtattoo.demo.app;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SimpleThemesDemo extends JFrame {
public SimpleThemesDemo() {
super("SimpleThemesDemo-Application");
// setup menu
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
menu.setMnemonic('F');
JMenuItem menuItem = new JMenuItem("New");
menu.add(menuItem);
menuItem = new JMenuItem("Open");
menu.add(menuItem);
menuItem = new JMenuItem("Save");
menu.add(menuItem);
menuItem = new JMenuItem("Save as");
menu.add(menuItem);
menu.addSeparator();
menuItem = new JMenuItem("Exit");
menuItem.setMnemonic('x');
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, KeyEvent.
ALT_MASK));
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.exit(0);
}
});
menu.add(menuItem);
menuBar.add(menu);
setJMenuBar(menuBar);
// setup the widgets
JPanel contentPanel = new JPanel(new BorderLayout());
contentPanel.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));
JTree tree = new JTree();
tree.expandRow(3);
tree.expandRow(2);
tree.expandRow(1);
JScrollPane westPanel = new JScrollPane(tree);
JEditorPane editor = new JEditorPane("text/plain", "Hello World");
JScrollPane eastPanel = new JScrollPane(editor);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true,
westPanel,eastPanel);
splitPane.setDividerLocation(148);
contentPanel.add(splitPane, BorderLayout.CENTER);
setContentPane(contentPanel);
// add the listeners
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
// show the application
setLocation(32, 32);
setSize(400, 300);
setVisible(true);
} // end CTor SimpleThemesDemo
public static void main(String[] args) {
try {
// setTheme(String themeName, String licenseKey, String logoString)
com.jtattoo.plaf.acryl.AcrylLookAndFeel.setTheme("Green", "INSERT YO
UR LICENSE KEY HERE", "my company");
// select the Look and Feel
UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
// start the demo application
new SimpleThemesDemo();
} catch (Exception ex) {
ex.printStackTrace();
}
} // end main
} // end class SimpleThemesDemo
--------------------------------------------------------------------------------
--------
How to change the default look and feel.
Place the JTattoo.jar file in the (java_home)/lib/ext folder. Open or create the
swing.properties file in the (java_home)/lib folder. Insert the following line:
swing.defaultlaf=com.jtattoo.plaf.mcwin.McWinLookAndFeel
Java applications which do not explicitly set the look and feel will now be show
n with the McWinLookAndFeel.
-----------------------------------------------------------------------
How to change the look of NetBeans.
To change the look of NetBeans you have to edit the netbeans.conf file. You can
find this file in the XXX/netbeans/etc folder where XXX stands for the relative
path of your NetBeans installation. Open this file in a text editor and change t
he following line
netbeans_default_options="-J-Xms32m -J-Xmx128m -J-XX:PermSize=32m -J-XX:MaxPermS
ize=96m -J-Xverify:none"
to
netbeans_default_options="-J-Xms32m -J-Xmx128m -J-XX:PermSize=32m -J-XX:MaxPermS
ize=96m -J-Xverify:none -laf com.jtattoo.plaf.smart.SmartLookAndFeel"