System Tray - double click icon to set visible


I have this code working just fine, one option I want is to use a double-click on the icon in the system tray to set the application visible again. I am thinking of using a mouse listener but not sure where I would put it or would I use a window listener

Posted On: Wednesday 17th of October 2012 06:29:17 AM Total Views:  123
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




JButton clicked once, action done twice

Greetings all, Initially, I am not supplying code because I do not think it will help too much, but if anyone wants to see a bit, I can provide it. In short, I have a dialog box with a bunch of fields and a save button. the save button implements an action listener that calls the save(). It reads the fields, creates an instance of another class and calls the methods to have it saved to my database. The problem is, that when I click once on button, the save() is called twice. The only thing I can think of is that I should be using a mouseAdapter or mouseListener instead of an actionListener. Can anyone confirm this
VIEWS ON THIS POST

92

Posted on:

Tuesday 25th September 2012
View Replies!

Draw multiple circles on mouse click

Hi all, So far i managed to get a circle to show itself on the JPanel when the mouse is clicked. The only problem i have is that it doesn't show multiple circles when clicked, instead it deletes the pervious one. I have a method called paint() where the graphics is drawn. public void paint(Graphics g) { //Conversion to 2D graphics Graphics2D g2d = (Graphics2D)g; super.paint(g2d); //Enables antialiasing to the graphics object g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int red = (int) (Math.random()*256); int green = (int)(Math.random()*256); int blue = (int)(Math.random()*256); g2d.setColor(new Color(red, green, blue)); g2d.drawString("I am a circle", mouseX, mouseY); g2d.fillOval(mouseX, mouseY, 20, 20); }
VIEWS ON THIS POST

90

Posted on:

Tuesday 25th September 2012
View Replies!

clicking buttons programatically

hi, i have a webpage developed using html consisting of few buttons. normally we will click the buttons manually either by using mouse or keyboard. i need a help regarding how should i click those buttons programatically. that is when ever we execute a java program the button action should be performed same as when we clicked it manually.
VIEWS ON THIS POST

90

Posted on:

Wednesday 26th September 2012
View Replies!

I need help to display images on the panel by clicking

This is my FlowerImage class: import javax.swing.*; public class FlowerImage { java.awt.Point _location; java.awt.Image _fImage; public FlowerImage(java.awt.Image image, java.awt.Point loc){ _fImage = image; _location = loc; FlowerImage flower = new FlowerImage(new ImageIcon("daffodil1.gif").getImage(),loc); } public java.awt.Point getLoc() {return _location;} public int getX() { return (int)_location.getX();} public int getY() {return (int) _location.getY(); } public java.awt.Image getImage() {return _fImage; } }
VIEWS ON THIS POST

169

Posted on:

Wednesday 26th September 2012
View Replies!

Trying to get a square change color on button click

EDIT: Obviously a beginners question! Probably in the wrong forum, please feel free to move mods! Apologies! I thought I'd help myself understanding the GUI and ActionListener proces a bit better by sussing out how to do something simple like putting a button and a rectangle on a screen and then having it change color from blue to red on buttonclick. Appears I've ended up in a swamp and everytime I move I get sucked farther in. I soon found out I have no clue how to easily change the color of something when clicking a button so I thought I'd fake it first by simply running a different color panel on mouseclick. And that failed miserably too! Trying to use the boolean swoosh in two different classes is not the way to go. So a little help, hint or push in the right direction would be greatly appreciated! import javax.swing.*; import java.awt.*; import java.awt.event.*; public class KnopOefen implements ActionListener { JFrame frame; public static void main(String[] args) { boolean swoosh = true; KnopOefen knop = new KnopOefen(); knop.go(); } public void go() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Click to make the square red!"); button.addActionListener(this); Rectangle recty = new Rectangle(); frame.getContentPane().add(BorderLayout.SOUTH, button); frame.getContentPane().add(BorderLayout.CENTER, recty); frame.setSize(300,300); frame.setVisible(true); } public void actionPerformed(ActionEvent event) { boolean swoosh = false; KnopOefen knip = new KnopOefen(); knip.go(); } }
VIEWS ON THIS POST

189

Posted on:

Wednesday 26th September 2012
View Replies!

table generation upon clicking start button

The following code reads a csv file and displays that as table. I would like to add 3 buttons say Start, stop and insert. On clicking Start the table should be generated. On clicking reset, the table should be cleared. package AWTTable; /** * * @author Admin */ import java.io.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; public class Csv2TableModel { public static void main(String[] args) { try { String datafile = "C:/Users/Admin/Documents/companylist.csv"; FileReader fin = new FileReader(datafile); DefaultTableModel m = createTableModel(fin, new Vector(Arrays.asList( new String[] { "a", "b", "c" }))); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(new JTable(m))); f.setSize(200, 300); f.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } /** * * * @param in A CSV input stream to parse * @param headers A Vector containing the column headers. If this is null, it's assumed * that the first row contains column headers * * @return A DefaultTableModel containing the CSV values as type String */ public static DefaultTableModel createTableModel(Reader in, Vector headers) { DefaultTableModel model = null; Scanner s = null; try { Vector rows = new Vector(); s = new Scanner(in); while (s.hasNextLine()) { rows.add(new Vector(Arrays.asList(s.nextLine() .split("\\s*,\\s*")))); } if (headers == null) { headers = rows.remove(0); model = new DefaultTableModel(rows, headers); } else { model = new DefaultTableModel(rows, headers); } return model; } finally { s.close(); } } }
VIEWS ON THIS POST

70

Posted on:

Thursday 27th September 2012
View Replies!

how to manage the dissmissal of joptionpane when any button is clicked

Hi! is there a way to manage the buttons of JOptionPane such that they do not just close when any of them is closed. For example I'm creating a program whereby the user enters username and password through JOptioPane which should only be dismissed if the user enters correct values and clicks ok or when the user clicks cancel. The problem is by default clicking any button dismisses the dialog. I've done all the necessary work of accessing the database and comparing database values with user values when ok is clicked but I don't know how to control the dialog not to dimiss after ok is clicked and username and password don't match. The code fragment for my JOptionPane is shown below JOptionPane.showConfirmDialog(mainFrame, panel, "Enter username and password", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
VIEWS ON THIS POST

73

Posted on:

Friday 28th September 2012
View Replies!

Issue with click event on a custom JToggleButton in a JTable

, This is basically a repost of my question since i have not been able to find a solution so far http://stackoverflow.com/questions/9588384/placing-jtogglebutton-with-jpanel-within-into-a-jtable-cell The issue is, that i have a custom button in a table and the click event gets triggered only on the second click in the table cell. If i remove the panel within the custom button it works as intended (i need this panel though). I tried using JLayeredPane instead but faced the same issue that only on second click does the button get clicked. Any suggestions how to have the click event propagated immediately to the button Below is a sample code. Many thanks. package sandbox; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.AbstractCellEditor; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.JToggleButton; import javax.swing.table.AbstractTableModel; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableModel; public class ClickableCustomButtonInTable extends JToggleButton { public ClickableCustomButtonInTable() { Dimension d = new Dimension(100, 100); JLabel lFirst = new JLabel("1st label"); lFirst.setPreferredSize(d); JLabel lSecond = new JLabel("2nd label"); lSecond.setPreferredSize(d); JPanel panel = new JPanel(); panel.setOpaque(true); panel.setLayout(new BorderLayout()); panel.add(lFirst, BorderLayout.NORTH); panel.add(lSecond, BorderLayout.SOUTH); add(panel); //if i comment this line out the click event gets triggered immediately as expected addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Button clicked"); } }); } private static class CustomButtonRenderer implements TableCellRenderer { private final ClickableCustomButtonInTable button = new ClickableCustomButtonInTable(); @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { return button; } } private static class CustomButtonEditor extends AbstractCellEditor implements TableCellEditor { private final ClickableCustomButtonInTable button = new ClickableCustomButtonInTable(); @Override public Object getCellEditorValue() { return button.getText(); } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { return button; } } public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(new Dimension(200, 200)); Container content = frame.getContentPane(); TableModel model = new AbstractTableModel() { @Override public Object getValueAt(int rowIndex, int columnIndex) { return null; } @Override public int getRowCount() { return 1; } @Override public int getColumnCount() { return 1; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return true; } @Override public Class getColumnClass(int columnIndex) { return ClickableCustomButtonInTable.class; } }; JTable table = new JTable(model); // table.setBounds(new Rectangle(0, 0, content.getWidth(), content // .getHeight())); table.setRowHeight(frame.getHeight()); table.setDefaultRenderer(ClickableCustomButtonInTable.class, new CustomButtonRenderer()); table.setDefaultEditor(ClickableCustomButtonInTable.class, new CustomButtonEditor()); content.add(table); content.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
VIEWS ON THIS POST

88

Posted on:

Friday 28th September 2012
View Replies!

own coordinate system in JPanel

Can anyone help is there a way to set my own coordinate system in JPanel
VIEWS ON THIS POST

50

Posted on:

Friday 28th September 2012
View Replies!

Window (Game) not registering mouse clicks occasionally

Hi folks, I've been learning Java and OOP in my spare time for fun lately. After finishing with Head First Java, I'm currently reading through Daniel Liang's excellent Introduction to Java Programming Comprehensive and Core Java Vol 1. I'm currently programming some of the exercise problems at the end of the Event driven programming chapter of the first book. Here is the exercise problem: Write a program that displays a circle of radius 10pixels filled with a random color at a random location on a panel. When you click the circle, it is gone and a new random-color circle is displayed at another random location. After twenty circles are clicked, display the time spent in the panel. I've coded this up and it works perfectly, except that when clicking in rapid succession, some of the clicks are not registered. I have noticed this with other programs I have written as well, and when I run the compiled class files provided by the author of the book (to try running all the exercise problems), I observe a similar behavior. Is this a concurrency issue due to conflicts with the GUI EDT I haven't read up on threads and concurrency yet, but if that is the case, I'd like to identify where the issue is being produced. With the bug as is, this exercise is a bit pointless because you can never get a great "score" due to the unregistered click events. PS - I have added in some stuff to avoid bugs when resizing the window. I know that I could have set it to not be resizable, but I was just playing around with the code to see if I could handle that case without making a hash of things. Also, I'd appreciate any general comments about the program and what I could do to improve it. import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class Exercise16_27 extends JFrame { public Exercise16_27() { add(new MoveCircleGamePanel()); } public static void main(String [] args) { JFrame frame = new Exercise16_27(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); } }
VIEWS ON THIS POST

63

Posted on:

Sunday 30th September 2012
View Replies!

How to close a JMenu without clicking outside it?

A Jmenu automatically collapses, if we click anywhere outside it. Is there a way to replicate this action without clicking I tried menu.setSelected(false). This un-selects the menu but it still remains open. I tried this ans still the menu and menu item is un-selected but they remain open for(Component c : menu.getMenuComponents()) { if(c instanceof JMenuItem) { ((JMenuItem)c).setSelected(false); } }
VIEWS ON THIS POST

80

Posted on:

Sunday 30th September 2012
View Replies!

disable selection on double click in textpane

For my application i want to disable the textpane from selecting a word when double click is performed on the word. Is there a way to do this
VIEWS ON THIS POST

159

Posted on:

Tuesday 2nd October 2012
View Replies!

Setting the cursor in a text field after clicking a button?

I have a JButton programmed in a SWing GUI that when I click it, it will take the score and put it into a JLabel somewhere else. The thing is when I click the JButton the cursor doesn't reset back to the JTextField. How would I go about doing that
VIEWS ON THIS POST

144

Posted on:

Wednesday 3rd October 2012
View Replies!

displaying the file name of a pendrive in a text area by clicking a button

hi .... my project is on pen drive where deer l b a display screen and with blue tooth functionality... i have a code which is displaying the list name but not in the text area... please help me out in this .... import java.io.File; import java.awt.*; import java.awt.event.*; public class DirectoryReader { static int spc_count=-1; static void Process(File aFile) { spc_count++; String spcs = ""; for (int i = 0; i < spc_count; i++) spcs += " "; if(aFile.isFile()) System.out.println(spcs + "[FILE] " + aFile.getName()); else if (aFile.isDirectory()) { System.out.println(spcs + "[DIR] " + aFile.getName()); File[] listOfFiles = aFile.listFiles(); if(listOfFiles!=null) { for (int i = 0; i < listOfFiles.length; i++) Process(listOfFiles[i]); } else { System.out.println(spcs + " [ACCESS DENIED]"); } } spc_count--; } public static void main(String[] args) { String nam = "H:/"; File aFile = new File(nam); // textArea.add(Process(aFile)); Button b; Frame frame=new Frame("Text Frame"); TextArea textArea=new TextArea("hello!Welcome to BLUE PEN world",4,30); frame.add(textArea); frame.setLayout(new FlowLayout()); frame.setSize(250,250); frame.setVisible(true); textArea.setEditable(true); frame.add(b = new Button(""),BorderLayout.CENTER); frame.add(b = new Button("ok"),BorderLayout.NORTH); frame.add(b = new Button("v"),BorderLayout.EAST); frame.add(b = new Button("^"),BorderLayout.WEST); frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } }
VIEWS ON THIS POST

174

Posted on:

Wednesday 3rd October 2012
View Replies!

Retrieve files from a remote system

I have got the following code to retrieve files from a remote system package my.RemoteConn; import com.jcraft.jsch.*; import java.awt.*; import javax.swing.*; import java.io.*; public class ScpFrom { /** * @param args */ public static void main(String[] arg) { if(arg.length!=2){ System.err.println("usage: java ScpFrom user@remotehost:file1 file2"); System.exit(-1); } FileOutputStream fos=null; try{ String user=arg[0].substring(0, arg[0].indexOf('@')); // Gets the username arg[0]=arg[0].substring(arg[0].indexOf('@')+1); String host=arg[0].substring(0, arg[0].indexOf(':')); // Gets the hostname String rfile=arg[0].substring(arg[0].indexOf(':')+1); // Gets the source file String lfile=arg[1]; // Gets the destination file String prefix=null; if(new File(lfile).isDirectory()){ prefix=lfile+File.separator; } JSch jsch=new JSch(); Session session=jsch.getSession(user, host, 22); // username and password will be given via UserInfo interface. UserInfo ui=new MyUserInfo(); session.setUserInfo(ui); session.connect(); // exec 'scp -f rfile' remotely String command="scp -f " +rfile; Channel channel=session.openChannel("exec"); ((ChannelExec)channel).setCommand(command); // get I/O streams for remote scp OutputStream out=channel.getOutputStream(); InputStream in=channel.getInputStream(); channel.connect(); byte[] buf=new byte[1024]; // send '\0' buf[0]=0; out.write(buf, 0, 1); out.flush(); while(true){ int c=checkAck(in); if(c!='C'){ break; } // read '0644 ' in.read(buf, 0, 5); long filesize=0L; while(true){ if(in.read(buf, 0, 1)
VIEWS ON THIS POST

57

Posted on:

Wednesday 17th October 2012
View Replies!

tray icon is not displaying

I have a small program, where i add a tray icon (with ico image) to the system tray and I am adding some menu-item to it etc. I can see the space in the system tray. I can see all the menu-items in it. when i click/right click. But the icon image is not showing. Earlier i assumed that, there is a possiblity that the ico image size is big and hence it is not showing. So i replaced it with small .ico image. but still it is not showing. can you please help me in the same Image image = icon.getImage(); System.out.println("image initialez"); TrayIcon ti = new TrayIcon(image, "Transformation Server Monitor",menu); System.out.println("tray icon initialez"); SystemTray tray = SystemTray.getSystemTray(); try { tray.add(ti); System.out.println("tray icon added"); //$NON-NLS-1$ } catch (AWTException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
VIEWS ON THIS POST

90

Posted on:

Wednesday 17th October 2012
View Replies!

swt trayicon send sms

hi, need some help please with swt trayicon. I have a swt trayicon, that displays tooltip messages but what I want is to display an alert message to the user of the trayicon at specific times, for instance a message is displayed to the user "you have worked 6 hours" this message is to be displayed after 6 hours of the trayicon invoked to the "systray". I dont want to stop there though, I also want an sms sent to the users moblie phone telling the user 6 hours has pasted. my first question is possible with swt trayicon second question does anyone know of an example where trayicon alerts user with a trayicon message and trayicon sends a sms to the users mobile phone as usual any help would be much appricated.
VIEWS ON THIS POST

104

Posted on:

Wednesday 17th October 2012
View Replies!

repaint happens only on mouseclick

I need to draw a graph in my app. I have created a separate class for it which extends jPanel. class optgr extends JPanel {
VIEWS ON THIS POST

96

Posted on:

Wednesday 17th October 2012
View Replies!

null pointer exception when clicking on JCheckbox

Hi all, I have overridden the JTable Header of my JTable to show a JCheckbox. I get this error each time I select/deselect. This error is only on JRE1.6. It does not occur on JRE1.5. Let me know if anybody has faced a similar problem and what is the solution Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException at javax.swing.plaf.basic.BasicTableHeaderUI$MouseInputHandler.mouseClicked(Unknown Source) at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
VIEWS ON THIS POST

62

Posted on:

Wednesday 17th October 2012
View Replies!