ticking clock in a swt application


Hi everybody.

I am building an SWT application which serves as a support for a board game (keeping score etc.) and as one of the features it contains a timer as a part of the interface. The idea is to have a label which displays seconds left of the clock and two buttons - start(stop) and reset.

I know this is a typical threading problem - I just need a thread which would tick every second and notify the label about it. However I can't fathom how to code this. I have tried with Timer and TimerTasks, but I always seem to get "org.eclipse.swt.SWTException: Invalid thread access".

Can someone please help me and tell me how to do this
Posted On: Thursday 18th of October 2012 09:33:21 PM Total Views:  99
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




Eclipse swt property strings

hallo , im working with eclipse swt to embed office files into jframes, is there a way to know all the property strings one can change, for example when you write: OleControlSite controlSite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer"); OleAutomation automation = new OleAutomation(controlSite); int[] rgdispid = automation.getIDsOfNames(new String[]{"LocationName"}); int dispIdMember = rgdispid[0]; Variant result = automation.getProperty(dispIdMember); System.out.println("The Web Browser is currently viewing the URL "+result.getString());
VIEWS ON THIS POST

100

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!

swt.jar

This is the first time I use SWT, please see the following program. I don't have swt.jar in my system. Would anyone instruct me how to make it work. I know I need swt.jar in my system. Where can I download the jar file and how to install it.
VIEWS ON THIS POST

104

Posted on:

Wednesday 17th October 2012
View Replies!

dynamically filling of embedded swt_awt frame

hello all, i wrote a plug-in which displays a empty awt frame within an editor (org.eclipse.ui.editors) by using the SWT_AWT bridge. by the using of plugin: exists any way to get the embadded frame from my open editor i want to load dynamically any awt-frames from any java-project. is that possible for suggestions
VIEWS ON THIS POST

109

Posted on:

Wednesday 17th October 2012
View Replies!

Problems using JTabbedPane In a GUI application

Hi I making a GUI application, that uses JTabbedPane. Each of the tab panes need to contain the same Jlabels. I will add textboxes with specific information, once the Tab GUI's are completed. I created button objects, they seem to appear correctly on the tab panes. But the labels seem to not appear, on the other tab panes. I am having problems in that the labels display on the last tab created, and not on the others. I have included my code below. Can anyone help /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author rrodriguez */ package tabbedpaneproject; import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JTabbedPane; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.SwingConstants; public class JTabbedPanelFrame extends JFrame { JLabel SltInput = new JLabel("Log Source File : "); JLabel SltSource = new JLabel("Log Output File : "); JLabel SltWaterResources = new JLabel("Total Water Resources : "); JLabel SltFuelResources = new JLabel("Total Fuel Resources : "); JLabel SltInitFuel = new JLabel("Initial Fuel Amount : "); JLabel SltInitWater = new JLabel("Initial Water Amount : "); JLabel SltTotalWater = new JLabel("Total Water Consumed : "); JLabel SltTotalFuel = new JLabel("Total Fuel Consumed : "); JLabel SltScenarioTime = new JLabel("Scenario Time : "); // set up GUI public JTabbedPanelFrame() // line 13 error { super( "JTabbedPane Demo " ); int panel_index = 1; int count = 2; JTabbedPane tabbedPane = new JTabbedPane();// create JTabbedPane /* (SltInput); (SltSource); (SltScenarioTime); (SltWaterResources); (SltFuelResources); (SltInitWater); (SltTotalWater); (SltTotalFuel);*/ JPanel locinfoPanel = new JPanel(); // locinfoPanel.add(SltInput); // locinfoPanel.add(SltSource); // locinfoPanel.add(SltWaterResources); // locinfoPanel.add(SltFuelResources); for(int index = 0; index < count; index++) { // set up panel and add it to JTabbedPane JLabel label = new JLabel( "panel " + panel_index ); JPanel panel = new JPanel(); // create third panel // JPanel locinfoPanel = new JPanel(); locinfoPanel.add(SltInput); locinfoPanel.add(SltSource); locinfoPanel.add(SltWaterResources); locinfoPanel.add(SltFuelResources); panel.setLayout( new BorderLayout() ); // use borderlayout //panel.add( new JButton( "North " + panel_index), BorderLayout.NORTH ); panel.add(locinfoPanel, BorderLayout.NORTH); panel.add( new JButton( "West " + panel_index), BorderLayout.WEST ); panel.add( new JButton( "East " + panel_index), BorderLayout.EAST ); panel.add( new JButton( "South " + panel_index), BorderLayout.SOUTH ); panel.add( label, BorderLayout.CENTER ); tabbedPane.addTab( "Tab " + panel_index, null, panel, panel_index + " Panel" ); add(tabbedPane); panel_index++; } setSize(750, 750); setVisible(true); } // end JTabbedPaneFrame constructor public static void main(String[] args) { new JTabbedPanelFrame(); } } // end class JTabbedPaneFrame
VIEWS ON THIS POST

64

Posted on:

Wednesday 17th October 2012
View Replies!

Exception in thread "AWT-EventQueue-0" org.eclipse.swt.SWTException: Invalid thread access

, For my application I have created a menu in the system tray. When you click left you get some dynamic data and when you click right on my menu you get a screen to add a new dynamic menuitem to my system tray menu. but when I try to add something to that menu I get this error: Exception in thread "AWT-EventQueue-0" org.eclipse.swt.SWTException: Invalid thread access this is my code: import java.awt.Frame; import java.awt.Dimension; import javax.swing.JButton; import java.awt.BorderLayout; import javax.swing.SwingConstants; import java.awt.event.KeyEvent; import java.awt.Rectangle; import javax.swing.JTextField; import javax.swing.JLabel; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; public class Test3 extends Frame { private static final long serialVersionUID = 1L; private JButton jButton = null; private JTextField txtInput = null; private JLabel lblInput = null; private JLabel lblResult2 = null; static Display display = new Display (); static Shell shell = new Shell (display); // @jve:decl-index=0: static MenuItem testMi = null; /** * This method initializes jButton * * @return javax.swing.JButton */ private JButton getJButton() { if (jButton == null) { jButton = new JButton(); jButton.setHorizontalTextPosition(SwingConstants.CENTER); jButton.setMnemonic(KeyEvent.VK_UNDEFINED); jButton.setBounds(new Rectangle(504, 246, 97, 29)); jButton.setText("Click"); //jButton.setSize(0,80); //jButton.addActionListener(new java.awt.event.ActionListener()); jButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent e) { //System.out.println("mouseClicked()"); // TODO Auto-generated Event stub mouseClicked() lblResult2.setText(txtInput.getText()); testMi.setText("Dynamic"); } }); //jButton.setRolloverEnabled(false); //jButton.setPreferredSize(new Dimension(50, 10)); } return jButton; } /** * This method initializes txtInput * * @return javax.swing.JTextField */ private JTextField getTxtInput() { if (txtInput == null) { txtInput = new JTextField(); txtInput.setBounds(new Rectangle(187, 73, 416, 22)); } return txtInput; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Test3 application = new Test3(); application.initialize(); application.setVisible(true); Image image = new Image (display, 16, 16); final Tray tray = display.getSystemTray (); if (tray == null) { System.out.println ("The system tray is not available"); } else { final TrayItem item = new TrayItem (tray, SWT.NONE); item.setToolTipText("SWT TrayItem"); item.addListener (SWT.Show, new Listener () { public void handleEvent (Event event) { System.out.println("show"); } }); item.addListener (SWT.Hide, new Listener () { public void handleEvent (Event event) { System.out.println("hide"); } }); final Menu mainMenu = new Menu (shell, SWT.POP_UP); for (int i =0; i
VIEWS ON THIS POST

112

Posted on:

Wednesday 17th October 2012
View Replies!

Java plotting application

Hi! I'm new here. I've been pulling my hair for a week or so, because my teacher of programming can't understand that I have no time to really get into the Java graphics programming. I'm good at programming in C++ and C# but not Java. He set us the deadline of 1 week (I'm already 4 days late) but he made an exception for me and I have to send him the completed project on friday. I'm working on a few projects at the moment, many of which have much closer deadlines than this one (a few for tomorrow, the others for the day after tomorrow). My assignment is to write a graphical application with which a user can draw linear (f(x)=a*x+n), square (f(x)=ax^2+bx+c) ang logarithm function (f(x) = a*log(x)). I've tried to implement many samples on the internet but with no success. There sould be no complex function parsing. The user inputs only the basic function parameters (a, b, c, n) using a textbox. The main reason is no experience in Java programming (only C# and C++). As I've mentioned before, I'm experiencing a great lack of time so I would very very grateful to people who would be ready to help me out. I'd rather not put any code here as it's a mess and it doesn't work at all. I've created at least 20 new project (Java Application and Java Desktop Application) which tells you I'm a failure.
VIEWS ON THIS POST

62

Posted on:

Wednesday 17th October 2012
View Replies!

i want to use cardlayout for my application

please how do i use a cardlayout to display 3-4 panels of medium sized frame. i also have problems installing sqlserver 2005 on my machine which uses vista home premium.please help me solve these problems
VIEWS ON THIS POST

69

Posted on:

Wednesday 17th October 2012
View Replies!

Stand alone application.

Guys, I am new to programming and developing application. Well I have to develop a standalone application, Could someone please guide me how do i go about developing it.step by step understanding...like what all i need to develop it..how do i kick off etc.
VIEWS ON THIS POST

66

Posted on:

Wednesday 17th October 2012
View Replies!

Regarding Usage of Web Services In desktop Swing application

hi, Is there any way to manage a swing desktop application,through web services. regards, Sachindra
VIEWS ON THIS POST

38

Posted on:

Wednesday 17th October 2012
View Replies!

GUI Pieces and Parts Not Sticking! Help!

As you will soon catch on, I'm very, very unknowledgeable about Java...well, any programming really. I'm just learning. I've been trying to sort out exactly what I need to create a GUI interface for a program I've already written. And, yes, the GUI interface is an assignment. My problem is this: what do I need and in what order or structure do I code it (Here's a little background: I've been studying the simplest chapter on GUI components in my text book, as well as referencing the Java API and my three Java for Dummies books (yep, 3). I think I understand that I need a JFrame, JTextFields (for user input), a JCheckBox could be used, JOptionPanes (for input dialog and message dialog), and a JComboBox for selecting from a list of choices. Question: Did I leave any important component out Question: Should I use JTextfields (but make them uneditable) to show the result of calculations based on user input or is there a better component Question: Do I need to nest a component (like JTextField) inside another component class If yes, which component (I'll do my best to figure out how to nest it if someone will just give me little hint.) I'm sorry I'm having to ask this, but I have a disorder that makes it very hard to focus when I'm under stress (and I've had some doozies hit me the last two weeks). This is all so new, and so much. I just need a little help in unraveling it. , The subject line was just me trying to laugh off my frustration--GUI (gooey) stuffy is usually sticky. That's all. I do everything small, already. I'm just learning so nothing is a bigger headache than 10 error messages and not having a clue what the real problem is. So, I write in pieces, compile, execute, and debug before I add anything new. However, I don't know exactly how to fit these GUI components together. The examples I have to go by are tiny programs, not so much pieces put together. I have an example for labels; I have an example for text fields; I have an example for check boxes, one for combo boxes, etc. But they are separate little programs. I do not have one cohesive example of all of these components represented in an application. Do you have a better understanding of my problem
VIEWS ON THIS POST

21

Posted on:

Wednesday 17th October 2012
View Replies!

org.eclipse.swt.SWTException

i created one thread and in that thread i am creating another thread but i am getting this exception org.eclipse.swt.SWTException: Invalid thread access at org.eclipse.swt.SWT.error(Unknown Source) at org.eclipse.swt.SWT.error(Unknown Source) at org.eclipse.swt.SWT.error(Unknown Source) at org.eclipse.swt.widgets.Display.error(Unknown Source) at org.eclipse.swt.widgets.Display.checkDevice(Unknown Source) at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) at chrriis.dj.nativeswing.NativeInterfaceHandler.dispatch(NativeInterfac eHandler.java:300) at chrriis.dj.nativeswing.NativeInterfaceHandler.runEventPump(NativeInte rfaceHandler.java:293) at com.instacoll.livedocuments.oo.userinterface.ManageDocuments.showMana geApp(ManageDocuments.java:1615) at com.instacoll.livedocuments.oo.miscellaneous.InstaSecureTray$3$1.run( InstaSecureTray.java:208) org.eclipse.swt.SWTException: Invalid thread access at org.eclipse.swt.SWT.error(Unknown Source) at org.eclipse.swt.SWT.error(Unknown Source) at org.eclipse.swt.SWT.error(Unknown Source) at org.eclipse.swt.widgets.Display.error(Unknown Source) at org.eclipse.swt.widgets.Display.checkDevice(Unknown Source) at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) at chrriis.dj.nativeswing.NativeInterfaceHandler.dispatch(NativeInterfac eHandler.java:300) at chrriis.dj.nativeswing.NativeInterfaceHandler.runEventPump(NativeInte rfaceHandler.java:293) at com.instacoll.livedocuments.oo.userinterface.ManageDocuments.showMana geApp(ManageDocuments.java:1615) at com.instacoll.livedocuments.oo.miscellaneous.InstaSecureTray$3$1.run( InstaSecureTray.java:208) org.eclipse.swt.SWTException: Invalid thread access at org.eclipse.swt.SWT.error(Unknown Source) at org.eclipse.swt.SWT.error(Unknown Source) at org.eclipse.swt.SWT.error(Unknown Source) at org.eclipse.swt.widgets.Display.error(Unknown Source) at org.eclipse.swt.widgets.Display.checkDevice(Unknown Source) at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) at chrriis.dj.nativeswing.NativeInterfaceHandler.dispatch(NativeInterfac eHandler.java:300) at chrriis.dj.nativeswing.NativeInterfaceHandler.runEventPump(NativeInte rfaceHandler.java:293) [ May 19, 2008: Message edited by: ramesh kancherla ]
VIEWS ON THIS POST

101

Posted on:

Wednesday 17th October 2012
View Replies!

Do you use some Swing applications in your daily work?

I'm looking for some cool Swing applications. Which Swing applications do you use
VIEWS ON THIS POST

59

Posted on:

Wednesday 17th October 2012
View Replies!

almost working: change string labels of whole application

Hi! I've been trying to let the end user change the language of a menu. It's almost done, now I have a Menus class showing 3 items : File Help and Description In the File item you click in Configuration and there is the combo box where you select the language, you select for example Spanish and click the button and it changes the language of the 3 items above (File,Help and Description). To do that I have a Selector class where I declare the Locales and an updateString method that I call after setting the Resources. So far so good Now in the Description item I have a subitem named Test and in Test there's a panel named Conver with just some labels and a button, I'm trying to change the language of this panel too in my Configuration panel but does not work ... Here are the classes: import java.awt.event.*; import java.util.*; import javax.swing.*; public class Menus extends JFrame { public ResourceBundle res; private JMenuBar jmbarBarraDeMenus; private JMenu jmnuArchivo; private JMenu jmnuHelp; private JMenu jmnuDescriptiva;//agregu private JMenuItem jmnuAbrir; private JMenuItem jmnuConfigura; private JMenuItem jmnuUniva;//agregu //private javax.swing.JLabel jlbGradosC; public Menus() { Locale.setDefault(new Locale("en")); //Ingls res = ResourceBundle.getBundle("Resources"); setSize(500, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); initComponents(); updateStrings(); setVisible(true); } private void initComponents() { jmbarBarraDeMenus = new javax.swing.JMenuBar(); jmnuArchivo = new javax.swing.JMenu(); jmnuDescriptiva = new javax.swing.JMenu();//agregu jmbarBarraDeMenus.add(jmnuArchivo); jmnuHelp = new javax.swing.JMenu(); jmbarBarraDeMenus.add(jmnuHelp); jmbarBarraDeMenus.add(jmnuDescriptiva); jmnuAbrir = new javax.swing.JMenuItem(); jmnuArchivo.add(jmnuAbrir); jmnuConfigura = new javax.swing.JMenuItem(); jmnuArchivo.add(jmnuConfigura); jmnuUniva = new javax.swing.JMenuItem();//agregue jmnuDescriptiva.add(jmnuUniva);//agregu // jlbGradosC = new javax.swing.JLabel(); jmnuConfigura.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { jMenuConf_actionPerformed(e); } }); jmnuUniva.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { jMenuUniva_actionPerformed(e); //agregu } }); getContentPane().setLayout(null); setJMenuBar(jmbarBarraDeMenus); } private void updateStrings() { setTitle(res.getString("TITLE")); jmnuArchivo.setText(res.getString("FILE")); jmnuHelp.setText(res.getString("HELP")); jmnuAbrir.setText(res.getString("OPEN")); jmnuConfigura.setText(res.getString("CONFIGURATION")); jmnuDescriptiva.setText(res.getString("DESCRIPTIVE")); jmnuUniva.setText(res.getString("UNIVARIANTE")); } private void jMenuConf_actionPerformed(ActionEvent e) { Selector dlg = new Selector(this); res = ResourceBundle.getBundle("Resources"); updateStrings(); } private void jMenuUniva_actionPerformed(ActionEvent e)//Agregu esto { System.out.println("hello I'm hereeeeee"); Conver conv = new Conver(this); res = ResourceBundle.getBundle("Resources"); updateStrings(); } public static void main(String args[]) { new Menus(); } }
VIEWS ON THIS POST

152

Posted on:

Wednesday 17th October 2012
View Replies!

flash video (FLV) player in swt or swing application

Is it somehow possible to play flv files in an eclipse rcp application (which is based on swt) without using a webbrowser viepart Or in swing If one takes the webbrowser viewpart you get all the functionality you don't want like the contect menu, hot keys and so on. And - most important - you are not platform independent since you need flash. I checked google nbut found nothing.. perhaps I should consider to switch to apple's quicktime format. tony roth
VIEWS ON THIS POST

182

Posted on:

Wednesday 17th October 2012
View Replies!

How to run a SWT / JFace application

Can someone point me a web-site that will show me how to deploy a SWT application. I have the screen running fine in Eclipse, but I am unsure of how to build it and run it from a Windows icon. Do I have create a have to create .ear to include my application jar and swt.jar and jface.jar
VIEWS ON THIS POST

72

Posted on:

Thursday 18th October 2012
View Replies!

swt hyperlink

can anybody please tell me with an example how to provide hyperlink text using SWT.I mean on clicking the text it goes to web page, i got idea of using html,it worked ...but its nopt working when other components are used in SWT.
VIEWS ON THIS POST

123

Posted on:

Thursday 18th October 2012
View Replies!

stand alone SWT application

i m tring to run swt app with a bat file but console also opens while .bat running what i m doing wrong , or what more should i do to stop that also i need swt.jar for my app, & i m unnable to combine it with my jar i saw, there is lot at net , but unfortunately , i m not getting in it may be classpath prob, or else plz help thnx
VIEWS ON THIS POST

50

Posted on:

Thursday 18th October 2012
View Replies!

Time out a Swing application by inactivity

It should be possible to timeout a Swing application by user inactivity, but I have not been able to figure it out or find it in the Internet. I can set a timer as a mouse and key listener in the main frame, but event in internal frames or dialogs do not trigger the timer actions. Could someone please tell me how to do this
VIEWS ON THIS POST

48

Posted on:

Thursday 18th October 2012
View Replies!