Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-07-2008, 10:37 PM
Member
 
Join Date: Apr 2008
Posts: 1
elisabethkron@yahoo.co.uk is on a distinguished road
How to add SystemTray to JDesktopPane
I have a JDeskTopPane which holds many JInternalFrames. I want to create a SystemTray for the JDeskTopPane and on this I want to show which internal windows I am using.

I have created a class which calls the SystemTray, and puts the systemTray in a Jpanel. I can add this JPanel to an Internal Window but if I try to add it to the JDesktopPane it does not show up. Please help.

This is my class for the SystemTray.

import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.Toolkit;

public class SysTray implements ActionListener
{
protected JButton buttonOne, buttonTwo;
private JPanel barPanel = new JPanel(new FlowLayout());

public void actionPerformed(ActionEvent e)
{
JButton button = (JButton)e.getSource();
String ac = button.getActionCommand();

// Another way to identify source component:
if(ac.equals("Trace"))
System.out.println("ActionEvent set by buttonDebugging Trace");

if(button == buttonOne)
System.out.println("Ok");
if(button == buttonTwo)
System.exit(0);
}


public JPanel getContent()
{
buttonOne = new JButton("Debugging Trace");
buttonOne.setActionCommand("Trace");
// Set the actions
buttonOne.addActionListener(this);

barPanel.add(buttonOne);
return barPanel;
}

public JPanel createPane2Button() {
buttonTwo = new JButton("Stepper");
buttonTwo.setActionCommand("Stepper");
// Set the actions
buttonTwo.addActionListener(this);

barPanel.add(buttonTwo);
return barPanel;
}

private void barPanel(JButton buttonOne2) {
// TODO Auto-generated method stub

}

public void initSystemTray()
{
final TrayIcon trayIcon;

if (SystemTray.isSupported())
{
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage("cut.gif");
// .createImage("images/sysTray/logo.gif");

MouseListener mouseListener = new MouseListener()
{
public void mouseClicked(MouseEvent e)
{
System.out.println("Tray Icon - Mouse clicked!");
}
public void mouseEntered(MouseEvent e)
{
System.out.println("Tray Icon - Mouse entered!");
}
public void mouseExited(MouseEvent e)
{
System.out.println("Tray Icon - Mouse exited!");
}
public void mousePressed(MouseEvent e)
{
System.out.println("Tray Icon - Mouse pressed!");
}
public void mouseReleased(MouseEvent e)
{
System.out.println("Tray Icon - Mouse released!");
}
};

ActionListener exitListener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("Exiting...");
System.exit(0);
}
};

PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("Exit");
defaultItem.addActionListener(exitListener);
popup.add(defaultItem);

trayIcon = new TrayIcon(image, "Tray Demo", popup);

ActionListener actionListener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
trayIcon.displayMessage("Action Event",
"An Action Event Has Been Peformed!",
TrayIcon.MessageType.INFO);
}
};

trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(actionListener);
trayIcon.addMouseListener(mouseListener);

try
{
tray.add(trayIcon);
}
catch (AWTException e)
{
System.err.println("TrayIcon could not be added.");
}
}
else
{
System.err.println("System tray is currently not supported.");
}
}

public static void createAndShowGUI()
{

}



}
This is what I do in my main program when I try to add the systemtray.

SysTray sysTray = new SysTray();
sysTray.initSystemTray();

c1 = frame1.getContentPane();

JPanel barPanel = new JPanel(new BorderLayout());

barPanel.add(sysTray.getContent());

setDefaultCloseOperation( JInternalFrame.DISPOSE_ON_CLOSE );

frame1.pack();

// attach internal frame to desktop and show it
desktop.add(frame1);
desktop.add(barPanel,BorderLayout.SOUTH);

desktop.setVisible(true);
frame1.setVisible(true);


// show desktop

//setSize(1500,1000);
setSize(1000,700);
setVisible(true);
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 09:43 AM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org