Mixing JavaFX and Swing - java

i am writing a desktop application and i like to use swing components since javafx doen't provide a tabbedpane component. I can embed my custom swing component with SwingComponent.wrap(swingComp); So i have a swing tabbedpane which accepts swing components as child items. These child items are swing components too and they have two properties, title and content. Title is a string but content is a swingcomponent. How can i embed a javafx container again in those swing tabs? Thanks in advance.

I suspect that once you go from JavaFX to Swing using the wrap method, you can't return to JavaFX.
You probably need to specify a JPanel, then add the JTabbedPane to the JPanel. Your content would reference the JPanel.

Related

Do I need JPanel always?

I am now writing code simple GUI that's for start the game window. I only need Do you want to start game message and start button on the window. But I have a confusing concepts for the JFrame and JPanel. Actually, I thought I need to add JPanel to JFrame to add the other components such as JLabel, JButton,...etc. But I realized I don't actually need JPanel. I can just add the components simply use add(button), add(label) to JFrame. So why I need JPanel. And I think JFrame doesn't need JPanel but JPanel need JFrame. Am I understand correctly?
No, not always. A simple graphical user interface may be implemented by just adding components "directly" to a JFrame. But in order to get more flexibility, you would always use JPanels. For example, to employ different layouts in different parts of the GUI, to group certain components together, etc.
A JFrame is backed by a JRootPane, a part of which is a contentPane.
(image from Oracle Javadoc)
When you add components to a JFrame, you are really adding them to the content pane, e.g.: frame.getContentPane().add(Component).
A JFrame is a common starting scene of a Swing GUI application, while a JPanel is intended to be put in another scene (container). Since both content pane and a JPanel inherit from the same class (Container) you may use them in a similar manner, as far as adding components to them goes.
Do I need JPanel always?
No. Well, unless you need a Swing GUI. Then yes.
Another answer replied words to the effect. "No, you can add components direct to a frame" What they missed was that components added to a JFrame are added to the content pane (automatically). The content pane is a JPanel.
Having said that:
I (and many others) would recommend designing an app based around a main content panel, then adding that panel to a top-level container as needed. The top level container might be a JFrame, JWindow, JDialog, JOptionPane ..
What prompted the question? A JPanel is a very 'light weight' container (in more ways than one). A GUI can contain 1000s and not be burdened by doing so. Of course, that's a rare requirement, but just saying .. use panels as needed and don't worry about it.

How can I make custom Swing Containers?

I'm using Netbeans making an application in Swing. I've created a expandable/foldable drawer to be used in various situations that is meant to contain other GUI components.
This is similar to that of things like JPanel, JScrollPane, JTabbedPane, etc.
However, when I drag my component in to the designer, I cannot add any components under it. Is there a way to make my drawer a container?
Additional Info:
I have selected an example jPanel for instance, note how it has the '+' option. You can add child components under it. My own components, SideDrawer and ScrollableLoadableStripedTables have no such option. I'd like to be able to add it. I'd like to make my component, which extends JPanel act more like a container

Add Contents Dynamically to java swing jpanel

I am new to java. I was Developing apps in c# in past. I am using NetBeans gui designer. I have created a new JFrame in which layout is set to group layout in which there's scrollpane. I am adding components on runtime by using following code.
MyScrollPane.add(new javax.swing.JButton("Button1");
MyScrollPane.add(new javax.swing.JCheckBox("CheckBox1");
this.revalidate();
The problem is that these components are not showing in scrollpane.
Another problem is that there is no option for absolute layout. Because I want to generate a scrollable list which will get values from database and generate list at runtime.
NetBeans gui designer leverages GroupLayout to facilitate building of UIs. Adding components to this layout manager at runtime involves adding horizontal & vertical sequential groups which can be quite complex. A good reason to start coding using standard layout managers when starting starting out.
You shouldn't be adding anything to a JScrollPane (I assume MyScrollPane is a JScrollPane). Your buttons should be added the JPanel that is the view of the scroll pane.

Which Swing component for this design?

I am making a desktop application in Java and confused as to which swing component to use to achieve this result.
Here is the screenshot of the app.
I want to know the component for the content shown in the JScrollPane.
I am thinking of JList or JTable with Providing a Custom Renderer.
There will be alphabet headers and rows containing information.
Each row can be clicked to open a new window.
Row will also change its color on hovering.
there are two ways
JTreeTable (non_free Jide or SwingX)
Accordion (implemented in JavaFX)
You should go with JavaFX Accordion
Titled Pane and Accordion

How to automatically resize an AWT component after changing it's contents?

I have an AWT Label inside a Panel with FlowLayout. I want to dynamically change the Labels text and resize it to the required width.
I have only found answers to the Swing version of this problem (setPrototypeDisplayValue()), but I have to stick with AWT since this is a homework.
You should be able to call invalidate(), which will then tell the parent container (your Panel) to redraw itself.
http://download.oracle.com/javase/1.4.2/docs/api/java/awt/Container.html#invalidate()

Categories