swt buttons wont right-align


Hi ,

Good Day..

I need to create a dialog box for user to enter their name and implemented gridlayout.

I divide the shell widget into 3 columns and I want the first column be occupied by the label having it left aligned. Then I merge the last two columns and wanted the two buttons place right aligned into the shell.

But my problem is, the GUI does not draws itself correctly. Here's my code.

public void createGUI() { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Project1"); GridLayout layout = new GridLayout(); layout.numColumns = 3; layout.makeColumnsEqualWidth = true; layout.verticalSpacing = 20; shell.setLayout(layout); GridData gridData = new GridData(GridData.FILL_BOTH); Label label = new Label(shell, SWT.NONE); label.setText("Please Enter Your Name:"); label.setLayoutData(gridData); Composite composite = new Composite(shell, SWT.NONE); gridData = new GridData(GridData.FILL_BOTH); gridData.horizontalSpan = 2; composite.setLayoutData(gridData); layout = new GridLayout(); layout.numColumns = 1; composite.setLayout(layout); /**** Added to make it fit Label lblHidden = new Label(composite, SWT.NONE); gridData = new GridData(GridData.FILL_BOTH); gridData.heightHint = 1; lblHidden.setLayoutData(gridData); lblHidden.setVisible(false);*****/ gridData= new GridData(GridData.HORIZONTAL_ALIGN_END); Button cmdOK = new Button(composite, SWT.PUSH); gridData.widthHint =50; cmdOK.setLayoutData(gridData); cmdOK.setText("Ok"); Button cmdCancel = new Button(composite, SWT.PUSH); gridData= new GridData(GridData.HORIZONTAL_ALIGN_END); gridData.widthHint =50; cmdCancel.setLayoutData(gridData); cmdCancel.setText("Cancel"); gridData = new GridData(GridData.FILL_BOTH); gridData.heightHint = 15; gridData.horizontalSpan = 3; Text txtInput = new Text(shell, SWT.BORDER); txtInput.setLayoutData(gridData); shell.pack(); shell.open(); while(!shell.isDisposed()) { if(!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
Posted On: Monday 22nd of October 2012 02:56:32 AM Total Views:  92
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!

rounded buttons

How to create rounded buttons using swing . Same as the buttons that we see in windows calculator whose borders are circular rather than squared.
VIEWS ON THIS POST

69

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!

JGoodies FormLayout question place buttons at center

I am trying to learn JGoodies FormLayout. I started working with the Default FormBuilder and I am having trouble aligning 2 buttons at the centre of the panel. I need to do this: User Name Text Field Password Text Field .. .. .. Create Cancel The create and cancel buttons should appear bang on the centre of the panel. The buttons always appear on the left not on the center. The code that I am using: FormLayout layout=new FormLayout( "fill:pref,5dlu,fill:100dlu", ""); DefaultFormBuilder builder=new DefaultFormBuilder(layout,this); builder.setDefaultDialogBorder(); builder.appendSeparator("User Details"); builder.nextLine(); builder.append("&User ID", tfUserId); builder.append("&Password", tfPassword1); .. .. .. builder.appendSeparator(); builder.nextLine(); builder.append(ButtonBarFactory.buildCenteredBar(btnCreate, btnCancel));
VIEWS ON THIS POST

75

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!

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!

focussing swing buttons using tab key

I want to get focus on my swing buttons immediately when i open the page without the help of mouse for the first time.my code is working. but sometimes it is not working.here is my code.please reply what is the fault there code: public class AstMonitor extends JApplet implementsActionListener,FocusListener,Runnable { boolean keepTrying = true; Thread astThread; JButton sale = new JButton("12 Sale "); public void init() { resize(150,475); setForeground( java.awt.Color.black ); setBackground( new java.awt.Color(237,237,237) ); setFont( new Font("Tacoma", Font.PLAIN, 12) ); GridLayout gl; getContentPane().setLayout(new GridLayout(10,3)); nosale.setActionCommand("nosale"); nosale.addActionListener(this); this.getContentPane().add(nosale); nosale.setMnemonic('e'); nosale.setBackground(Color.pink); astThread = new Thread(this); astThread.start(); } public void focusGained(FocusEvent fe) { if(fe.getSource()==nosale) System.out.println(nosale.getLabel()+"gained"); if(fe.isTemporary()) System.out.println("Temporary Focus"); } public void focusLost(FocusEvent fe) { if(fe.getSource()==nosale) System.out.println(nosale.getLabel()+"lost"); }
VIEWS ON THIS POST

74

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!

making buttons circular

hey , im wondering if theres an easy way to make jbutton circular instead of rectangular. Suppose if i have a: class Mybutton extends JButton{ } im guessing i would have to override paintComponent but im not too good on the swing side of things. If anyone has any suggestions let me know. Sincely, Chris Dancy
VIEWS ON THIS POST

74

Posted on:

Thursday 18th October 2012
View Replies!

Enabling buttons on rowselection

Hi Can anyone give me a solution what to do to achieve my task
VIEWS ON THIS POST

51

Posted on:

Thursday 18th October 2012
View Replies!

Disappearing buttons

The constructGrid method constructs a grid of buttons. When first created after pressing the "new game button", the buttons are fine and visibile, but after you click one of the buttons or the frame background all of the buttons dissapear. Here is all of the code. Also, another smaller issue is that the menu bar appears above the top of the frame. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Javalization { private static void Construct() { JFrame.setDefaultLookAndFeelDecorated(true); final JFrame frame = new JFrame("Javalization v1.0"); final JFrame game = new JFrame("Javalization v1.0"); MenuBar menuBar = new MenuBar(); Menu menuFile = new Menu(); MenuItem menuFileExit = new MenuItem(); menuFile.setLabel("File"); menuFileExit.setLabel("Exit"); menuFileExit.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } } ); menuFile.add(menuFileExit); menuBar.add(menuFile); frame.setMenuBar(menuBar); JButton butan = new JButton("Exit"); JButton nGame = new JButton("New Game"); Container con = frame.getContentPane(); Container gameCon = game.getContentPane(); frame.setResizable(false); game.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); game.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel emptyLabel = new JLabel(""); emptyLabel.setLayout(null); emptyLabel.setPreferredSize(new Dimension(512,384)); emptyLabel.setBackground(Color.CYAN); frame.getContentPane().add(emptyLabel, BorderLayout.CENTER); JLabel gameLabel = new JLabel(""); gameLabel.setLayout(null); gameLabel.setPreferredSize(new Dimension(512,512)); gameLabel.setBackground(Color.CYAN); game.getContentPane().add(gameLabel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); game.pack(); game.setVisible(false); //Image icon = Toolkit.getDefaultToolkit().getImage("Logo.jpg"); //frame.setIconImage(icon); //game.setIconImage(icon); nGame.setBounds(80,304,100,50); butan.setBounds(206,304,100,50); butan.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae) { System.exit(0); }}); nGame.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent x) { frame.setVisible(false); game.setVisible(true); } }); con.add(butan); con.add(nGame); constructGrid(gameCon,500,500,25,25); } private static void constructGrid(Container container, int xPane, int yPane, int xSize, int ySize ) { int xMod = (xPane/xSize); int yMod = (yPane/ySize); int row = 0; int column = 0; int ConstructedCounter = (xMod*yMod) + 1; JButton [][] ButtonArray = new JButton[xMod][yMod + 1]; while (ConstructedCounter >= 0) { ConstructedCounter --; JButton current = new JButton(); current.setBounds(xMod * row + 50, yMod * column + 50, xMod, yMod); current.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent x) { } }); ButtonArray[row][column] = current; container.add(ButtonArray[row][column]); column++; if (column >= xMod) { column = 0; row ++; } JButton last = new JButton(); last.setBounds(xMod * row + 50, yMod * column + 50, xMod, yMod); ButtonArray[row][column] = last; container.add(ButtonArray[row][column]); } } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { Construct(); } }); } }
VIEWS ON THIS POST

54

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!

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
VIEWS ON THIS POST

98

Posted on:

Thursday 18th October 2012
View Replies!

opening and closing frames with buttons?

How would I go about creating a frame in which I could open and close other objects/frames in the style of a menu I have very little experience with GUIs and have found little examples of such code. I am trying to create a simple Point of Sale system in which after logging in, will display a page with 4 buttons that would each open a different object/frame/page (i.e. clicking on Invoice button would open Invoice creator object and effectively close the old menu).
VIEWS ON THIS POST

69

Posted on:

Sunday 21st October 2012
View Replies!

binding keys for use of buttons

, I am having a problem binding keys to buttons in netbeans. I have an app that has a textfield that gets input from a series of 8 buttons. i want to map the numpad to these buttons ONLY when the textfield is the focus. so far I have implemented a rough KeyPressed listener that filters VK_NUMPADX through an if statement, but this is problematic. First and foremost, the button i press is also added to the textfield, i.e. if i map VK_NUMPAD1 to essentially paste "", the textfield reads 1. Secondly, I have simply copy-pasted the contents of each button's action performed method into the if statements, which seems to be too brute force... how do i call the buttonActionPerformed method directly within this Keypressed method\t I hope i am clear enough to elicit a response
VIEWS ON THIS POST

61

Posted on:

Monday 22nd October 2012
View Replies!

Modify the height of rows in swt Table

I am fetching how can i modify the height of rows in swt Table. I used this code : table.addListener(SWT.MeasureItem, new Listener() { public void handleEvent(Event event) { event.gc.setLineWidth(varWidth); event.height = varHeight; } but the problem is that i can just increase the height of rows but not decreasing it. Can someone help me!
VIEWS ON THIS POST

80

Posted on:

Monday 22nd October 2012
View Replies!

org.eclipse.swt.SWTException: Widget is disposed

I'm new to SWT technologie, and when I was tring to create a multi forms aplication, I created a Button that opens an other Shell object : Display display = new Display(); final Shell shell = new Shell(display); final Shell ajouterForm = new Shell(shell,SWT.BORDER|SWT.CLOSE);
VIEWS ON THIS POST

75

Posted on:

Monday 22nd October 2012
View Replies!

Toggling radio buttons

I want to toggle the radio buttons using left right arrow key. The radio buttons are getting toggled using the tab key. Does any one know the solution to this -
VIEWS ON THIS POST

51

Posted on:

Monday 22nd October 2012
View Replies!