Sie sind auf Seite 1von 8

How to change themes.

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());
}
}
});

// add the listeners


addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
// show the application
setLocation(32, 32);
setSize(400, 300);
show();
} // end CTor ThemesDemo
public static void main(String[] args) {
try {
// setup the look and feel properties
Properties props = new Properties();
props.put("logoString", "my company");
props.put("licenseKey", "INSERT YOUR LICENSE KEY HERE");
props.put("selectionBackgroundColor", "180 240 197");
props.put("menuSelectionBackgroundColor", "180 240 197");
props.put("controlColor", "218 254 230");
props.put("controlColorLight", "218 254 230");
props.put("controlColorDark", "180 240 197");
props.put("buttonColor", "218 230 254");
props.put("buttonColorLight", "255 255 255");
props.put("buttonColorDark", "244 242 232");
props.put("rolloverColor", "218 254 230");
props.put("rolloverColorLight", "218 254 230");
props.put("rolloverColorDark", "180 240 197");
props.put("windowTitleForegroundColor", "0 0 0");
props.put("windowTitleBackgroundColor", "180 240 197");
props.put("windowTitleColorLight", "218 254 230");
props.put("windowTitleColorDark", "180 240 197");
props.put("windowBorderColor", "218 254 230");
// set your theme
SmartLookAndFeel.setCurrentTheme(props);
// select the Look and Feel
UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");
app = new ThemesDemo();
}
catch (Exception ex) {
ex.printStackTrace();
}
} // end main
} // end class ThemesDemo

------------------------------------------------------------------
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"

Copy the JTattoo.jar file into the XXX/netbeans/platform5/lib folder.

NetBeans before 4.0


To change the look of NetBeans you have to edit the ide.cfg file. You can find t
his file in the XXX/netbeans/bin folder where XXX stands for the relative path o
f your NetBeans installation. Open this file in a text editor and change respect
ively insert the following line
-ui com.jtattoo.plaf.aluminium.AluminiumLookAndFeel

Copy the JTattoo.jar file into the XXX/netbeans/lib folder.


Next time you start NetBeans you will be suprised.
---------------------------------------------------------------------
How to change the look of JBuilder.
To change the look of JBuilder you have to edit the user_xx.properties (where xx
stands for the country you live e.g. you live in Germany the correct filename i
s user_de.properties). You can find this file in your user home directory in the
.jbuilder folder (in JBuilder 2005 the name of the folder is .primetime2005). O
pen this file in a text editor and change respectively insert the following line
browser;look_and_feel=com.jtattoo.plaf.smart.SmartLookAndFeel
Copy the JTattoo.jar file into the XXX/jbuilder/lib folder. You can find this fo
lder in the relative path of your JBuilder installation.
Next time you start JBuilder you will be suprised.
---------------------------------------------------------------------
How to change the look of your application.
The following short code fragment shows you the way how to switch the Look and F
eel in your application. Be sure that the JTattoo.jar is in the java classpath,
if you want to run this demo. The easiest way is to copy the JTattoo.jar file in
to the (java_home)/jre/lib/ext folder.
/*
* Copyright 2005 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 MinFrame extends JFrame {
public MinFrame() {
super("Minimal-Frame-Application");
// setup menu
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
menu.setMnemonic("F");
JMenuItem 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 widgets
JPanel contentPanel = new JPanel(new BorderLayout());
contentPanel.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));
JScrollPane westPanel = new JScrollPane(new JTree());
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 listeners
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
// show application
setLocation(32, 32);
setSize(400, 300);
show();
} // end CTor MinFrame
public static void main(String[] args) {
try {
// select Look and Feel
UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");
// start application
new MinFrame();
}
catch (Exception ex) {
ex.printStackTrace();
}
} // end main
} // end class MinFrame
------------------------------------------------------------------

Das könnte Ihnen auch gefallen