AWT/Swing Event Threads vs SWT - Rob?


One of the more annoying things about Swing is handling heavy loaded methods from within events fired by a JButton, JMenuItem, etc. We actually had a pretty interesting discussion about it last may.

I am wondering if SWT's event handling addresses this issue or what was done to make this process easier for the developer when handling a large amount of code crunching and repainting of the app itself. What does the book cover in this regard
Posted On: Tuesday 23rd of October 2012 11:32:41 PM Total Views:  229
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




How to make my swing listen to key events?

Hi all, I am Chaitanya, I want to listen to key events on my JFrame. I have a JFrame and it consists a couple of internal frames. Each time i have to use the mouse to travel between the internal frames. So i decided to add a key listener to the JFrame and hear to F5 F6 F7 function keys. Pressing those keys will focus an internal window. Thats my idea. I added my JFrame to a DesktopPane and added key listener to desktopPane, it dint work. Then I tried with JFrame object. That also dint work. Can anyone tell me how to do this
VIEWS ON THIS POST

62

Posted on:

Monday 22nd October 2012
View Replies!

GlassPane not redirecting events to deeper components

Hi all -
VIEWS ON THIS POST

70

Posted on:

Monday 22nd October 2012
View Replies!

How to handle events in java

como evitar el uso de if cuando estoy manejando muchos botones en un formulario public void actionPerformed(ActionEvent e){ if(e.getSource()==btn1){ btn1.setText("X"); } else if(e.getSource()==btn2){ btn2.setText("Y"); }
VIEWS ON THIS POST

53

Posted on:

Monday 22nd October 2012
View Replies!

Dynamic TreeViewer: Add nodes in the tree expand event.

Hi Everybody, I am new to using SWT and stumbled onto a solution to my problem. I had searched the web for the solution with no success so I am sharing my solution in this forum in hopes that it will help others. the example dynamic trees used a button Action to insert the node. I could find no example of inserting nodes in events like expand or collapse. I am building an Eclipse plugin that uses a TreeViewer. The data for the tree comes from a web service and is too large to load everything upon initialization because it takes way too long. The thought is to dynamically load the nodes as needed. Initially only the first two levels are read. The reason for two levels is so that where a parent has children, the + symbol appears so that the branch can be expanded by the user. As the user expands branches, the needed nodes are loaded. The natural place to read the new nodes into the tree structure is in the TreeExpansionEvent. The only problem with this is that SWT disables the Display.refresh() methods in this event because the view is being updated. Loading up the new nodes in the event will change the domain model but it is not reflected in the view because the refresh is never actually executed. My first thought was to perform the loading of the new nodes in a new Thread but that too is prevented by SWT with an exception. The thread calling the refresh must be the same thread that created the Display. The trick is to use the Display.asyncExec() method. Here is my implementation of the treeListener listener: viewer.addTreeListener(new ITreeViewerListener() { public void treeCollapsed(TreeExpansionEvent event) { final TreeBranchDisposeThread dispose = new TreeBranchDisposeThread(); dispose.setEvent(event); event.getTreeViewer().getControl().getDisplay().asyncExec(dispose); return; } public void treeExpanded(TreeExpansionEvent event) { final UpdateTreeThread update = new UpdateTreeThread(); DctmObjectManager objectManager; try { objectManager = new DctmObjectManager(); } catch (ServiceInvocationException e) { // Auto-generated catch block e.printStackTrace(); return; } update.setObjectManager(objectManager); update.setEvent(event); event.getTreeViewer().getControl().getDisplay().asyncExec(update); } });
VIEWS ON THIS POST

59

Posted on:

Monday 22nd October 2012
View Replies!

JSpinner sending multiple events

I have a series of JSpinners that I am using in a GUI. I also have an inline change listener for each of them to handle the input, check it for out-of-range and pass the new value along to my software. The problem is that every second or third click on the spinner's up and down arrows generates 2 calls to stateChanged(). This forces my code to run twice, and since it can be a time consuming process when it runs, I am essentially doubling my run time for this process. I thought I could be clever and just trap the second call that occurred less that 50ms from the first one. That worked great! .... Except I realized that the second call I trapped actually carries the new value and the first call getting through carried the old one. So my question is this: Why am I having to jump through hoops to get data off my spinners Why is it sometimes tossing an extra call before it sends the real one I am expecting
VIEWS ON THIS POST

58

Posted on:

Monday 22nd October 2012
View Replies!

How to avoid mouse click event getting called when user press,drag and release the mouse

I have a Jtable component in my UI. I have implemented sorting of columns on click of column header using a Comparator.. The comparator is called in the mouseClicked event. My problem is.. when we try to resize the column i.e click on the border of columns drag and release... the mouse click event gets fired and that particular column gets sorted... I dont want this to happen.. This event of dragging and expand the column size must not trigger the mouseClick.. Is there any work around to avoid this\t I also tried giving empty implementation for mousePressed and mouseReleased events.... Please help..
VIEWS ON THIS POST

87

Posted on:

Monday 22nd October 2012
View Replies!

Prevent spaces from being accepted in a JTextField

Hi all, I have a JTextField and i don't want it to accept any Spaces or other characters.. How can i go about doing this\t Does anyone have sample code for me\t
VIEWS ON THIS POST

56

Posted on:

Monday 22nd October 2012
View Replies!

Regarding JTable mouse events

I have a JTable with some row data with one cell contains hyperlink on it, when we click on that link,it will take arguments of row data cell,and click it, it should open another dialog box, the table data should be displayed on this dialog box.please healp me as early as possible. Thank You in advance raja.tadi@tcs.com
VIEWS ON THIS POST

75

Posted on:

Monday 22nd October 2012
View Replies!

Enabling pass-through events between Layers in JLayeredPane

Hi all, I am trying to make a simple graph visualization GUI App, that reads nodes/edges info from a file and displays it as circles and lines. The user should be able to drag the circles around for better viewing and save the file (with the updated x,y node coordinates). I am using JLayeredPane with three layers. The lowest layer 0 is a background image, layer 1 are Nodes which are basically extended from JLabel and finally the top most layer is a JPanel whose paintComponent(Graphics g) function I use to draw lines representing edges between the nodes. The trouble I am having is that dragging the mouse on the screen will move the top-most layer (the panel with the edges) around instead of the nodes. Moving the JLabel nodes to the top using layeredPane.setlayer(node,2) resolves this problem but then the nodes hide the arrowheads of the edges. Is there a way the edges panel can remain on the top but pass the drag events to the nodes in the layer below Here is my code, I took out the file processing and node, link classes for simplicity.
VIEWS ON THIS POST

63

Posted on:

Monday 22nd October 2012
View Replies!

How to find the End task event ?

I had a swing based application.User will login to the application ,claim some tasks and start work on those.If he closes the window all the tasks he claimed will be released and logged out of the application.So that others can work on that tasks. If the user closes the window by ctrl+ALt+Del i.e. by end task the tasks he claimed is not getting released.Now I have to release the tasks even he closes the window by end task .Any of you please tell me how can I do that Basically I need to know how to capture the endtask event [ June 27, 2008: Message edited by: chandra mohan ]
VIEWS ON THIS POST

58

Posted on:

Monday 22nd October 2012
View Replies!

free e-book on core AWT and eventqueue internals

Can anyone give me a link for a good book for core AWT and event-queue internals. I mean a book that dwells really deep in to the topic.
VIEWS ON THIS POST

59

Posted on:

Monday 22nd October 2012
View Replies!

How can I catch the CTRL_C or CTRL_V event

Dear . How can I catch the Ctrl_C or Ctrl_V event in the StyledText widget. Which event listener should I use. KeyListener or anyone else.
VIEWS ON THIS POST

59

Posted on:

Monday 22nd October 2012
View Replies!

JTable ? handle Row lost focus event

Hi ranchers I have swing screen with JTable of user's list and additional information besides the table that changes on each row selection. This data is additional user data that doesn't fit the table. When the moving from one row to another I am collecting all additional row data to map and I attach it as hidden filed to the JTable model. Finally when the screen is submitted, all data is flushed to the db. My question is how I listen to the "row lost focus" and "row got focus" event in order to initiate the additional data according to the selected row, and save the data when moving to the next row Thank you Sharon
VIEWS ON THIS POST

70

Posted on:

Monday 22nd October 2012
View Replies!

mouse event for an array of object

Is it possible add moseDragged event for an array of rectangle...
VIEWS ON THIS POST

110

Posted on:

Monday 22nd October 2012
View Replies!

full-screen gray window problem and event handling problem

I want to show a fullscreen color and draw some lines. The program should work on Windows _and_ OS X. So I can not just set the window to the screen size. This will work on Windows, but not on OS X where the menu bar and dock will still be visible. I came up with the following little program which compiles fine, but shows a gray window shortly after the correct blue window is painted. Also the event handling will not work and I don't see an error. Pressing SPACE should exit the program, but doesn't. Looking forward any pointers. Here's the sample source: // ------- source full-screen begin -------------- import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FullScreen implements KeyListener { public void keyTyped(KeyEvent event) {} public void keyPressed(KeyEvent event) {} public void keyReleased(KeyEvent event) { if (event.getKeyChar() == KeyEvent.VK_SPACE) { System.exit(0); } } public void go() { JWindow window = new JWindow(); window.setVisible(true); window.addKeyListener(this); window.setBackground(Color.BLUE); window.setForeground(Color.WHITE); GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().setFullScreenWindow(window); } public void paint (Graphics g) { g.setColor(Color.WHITE); g.drawString(", World!", 50, 50); g.drawLine(0, 1000, 500, 0); } public static void main(String[] args) { FullScreen f = new FullScreen(); f.go(); } } //-------- source end -------------
VIEWS ON THIS POST

72

Posted on:

Monday 22nd October 2012
View Replies!

Editable combobox events

Hi , This particular problem has been bothering me for some time now.I have a simple application which consists of an editable combobox,a "send" button,a checkbox("echo") and a non editable textarea where information is logged. It works like this...a command is entered in the combo(which is also stored for later use in the combo),if echo is ticked then cmd and response are displayed in the textarea,else only response is displayed.To send the command,user can either click "send" button or press enter. I have used actionListener for the combo(not for the send button) since it fires a comboboxEdited and comboboxChanged whenever a change is done.This is doing the required task.But the problem occurs when there is no change in the combo(like if you just choose a previous command) and the user decides to click "send".Because there is no listener for send,nothing happens.But if i add a listener for send,then clicking of send results in data being logged twice(one for comboboxEdited and the other for send).I have also tried to use a keylistener for the combo,but tht also does not work.can someone throw some light on ths problem(sorry its been lengthy!)...
VIEWS ON THIS POST

59

Posted on:

Tuesday 23rd October 2012
View Replies!

mouseEntered and exited events to paint

im trying to create a program what when the mouse enters the left side of my window the background should change to red; if the mouse moves into the right side i need to change it to green. once i find the size of my window by saying d = yourFrame.getSize(); where do i calculate to find which side my mouse pointer is on at that time. could i use an if else statement in the mouseEntered and mouseExited and how could i create variables that define the left half of my window and right half
VIEWS ON THIS POST

60

Posted on:

Tuesday 23rd October 2012
View Replies!

problem to listen key board event

I have to listen CTRL key event on panel... can any one send sample code......
VIEWS ON THIS POST

64

Posted on:

Tuesday 23rd October 2012
View Replies!

JTextField and JButton: share the same event handler

I've a JFrame that has a JTextField and a JButton object. After typing something in the Textfield I want the JButton to be clicked when I hit Enter. How can I do it Does it have something to do with Actions Code example will be helpful.
VIEWS ON THIS POST

48

Posted on:

Tuesday 23rd October 2012
View Replies!

Detecting double-click events

I have a jList I want to have preform a task if the user double-clicks an entry. But I only see a mouseClicked(MouseEvent e) which fires with a single click.
VIEWS ON THIS POST

71

Posted on:

Tuesday 23rd October 2012
View Replies!