Java - Placing of few buttons and textboxes using SWT - java

I need to place few buttons one under another and few textboxes in the same way using SWT.
When I'm doing that, they are next to each other and I cannot change it even using
button1.setLocation(new Point(100,20));
button2.setLocation(new Point(400,10));
Can I add those things to something similiar to SWING's JPanel and move/position it freely as I need? Or maybe another solution? As to let You know - I cannot use SWING here. It has to be SWT. The reason is that I have already a chart made with SWT. The buttons and textboxes should be placed so they won't be covering my chart.

You can dynamically add a new control to the existing layout, but make sure you call the layout() on the parent Composite, where you have set the layout.
If you want to place a SWT control relative to another control, you can use org.eclipse.swt.layout.FormLayout.

Related

JavaFX switching between two panes in a UI

I need to give the user of a UI the option to switch between two border panes on clicking a button (or toggle switch or whatever).
The panes have the same job, size and position - it's just a different configuration so I don't want both of them there at the same time.
When designing the UI in SceneBuilder I cannot place them at them same spot and set one visible and one invisible - because SceneBuilder obviously doesn't know that I want to stack them on top of each other.
Is there a way I can include both of them in the UI but only show one at a time?
I'd appreciate any ideas :)!
What you are looking for is the CardLayout. See oracle's documentation on that: https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html
Instead of adding your Components directly to the Component with the BorderLayout, instead add a JPanel which is using the CardLayout. Add the two Components to this JPanel.
Unfortunately I have no way to test this with the SceneBuilder right now, but you'll figgure out, how that works ;)

Needing a component similar to JTabbedPane

I'm looking for a component like "JTabbedPane" in which I can design each tab separately and easily but I don't want the little square buttons with tab names in runtime! Instead, I want to activate each tab panel in my code. In fact, I want to have multiple "JPanel"s with same size and location (they have complete overlap) and I set visibility of each them manually in my code but the most importing thing is that I want to design each panel as easy as possible (like clicking on the tab names in design-time).
You could use CardLayout here to create your own overlapping panels as you have described. The visibility of each panel can be programmatically changed.

how to add panel/jpanel or any panel of any package to composite in java?? (using RAP, SWT)

I am creating an RAP application in JAVA.
i want to have a GUI like master detail. in which left side has panel that has a tree (like in windows 7) and on the right side there will be text fields which will be changing when different TreeItem is selected.
So i have to add two panels, but i don't know how to add panels into composite.
Please help
use frame.getContentPane() to the the master contentpane. Set its layout as new GridLayout(1,2).
Now create two panels and add them to the frame. http://docs.oracle.com/javase/tutorial/uiswing/components/panel.html
There are also more complex solutions depending on what you want to do. For example if you want to make the division of the space between left and right side cosumizable use jsplitpanes (http://docs.oracle.com/javase/tutorial/uiswing/components/splitpane.html).
SWT is one thing, Swing is another. If you already have something written in SWT and want to add Swing components, then you have to use the SWT/AWT Bridge. You can find a tutorial on how to do this here.

extended forms in java

I have this form where there are extendable controls like there's a textbox for the user to type and beside it is an add button which the user would use to add another textbox beneath the previous one.
My problem is i don't even know how to make that add button work so that another textarea/textbox would appear just beneath the previous control..im doing it in netbeans ide 7.0 and in design mode...
I have researching for quite a while now and i'm so confused already what to do..at least you could provide me with an idea not really the code.
You should create a Layout.
For your case (Form kinda layout) , it seems that you need GridLayout.
For example, please check this link for all type of layout or directly go to Grid Layout link.
Since you're going to be dynamically adding controls to your form, you'd simply want to put in a panel where you want the textbox and the button. Inside that panel place your textbox and button, you'd probably not want to use netbeans to do this, and use a LayoutManager like GridLayout. Now you'lld want to connect your button to an ActionListener that adds a textfiield to the panel.
See the Nested Layout Example for an example of (amongst other things) adding components to a GUI dynamically.

What is this component name

What is the name of the component in java Swing shown in the following link
http://www.scriptocean.com/template3.html
It is known as extended ListView in Android. But I want to know the same in Java Swing.
Do you mean this component ?
If so, to display it in Java, you have some choices.
If you want your items to be easily clickable (that's to say action senders), you would tend to use JButtons in a vertical BoxLayout 'ed JPanel
If you simply want to display items, then customize their display, you would undoubtly go the JList way. Also take a look at Swing tutorial, which is always of great help.
EDIT
Accordint o comment, to have an area below the button displaying content, you'll use the second solution with a twist. As all elements in Swing are in fact JComponents and can be put in thers, you'll use JPanel as JList elements. in each JPanel, you'll have ione button always visible and one sub-panel that is hidden at startup. When clicking the JButton, you'll simply show or hide the associated sub-panel. If you want to have some kind of effect, you can either
wait for the upcoming JavaFX transitions effects
Use Filthy Rcih Clients animations library (take a look at their links page).
There is no standard Swing component that behaves like in your example. But you can find something similar in the SwingX project : the JXTaskPane and JXTaskPaneContainer components.
Unlike your example, the sections are not exclusive. But you can achieve this exclusivity with a few lines of code.

Categories