Scenario : In NetBeans, you create Swing components via drag & drop and customize some properties via the given GUI.
Question : Later on, If you see the generated code of these components, either in source or by by right-clicking the component and selecting customize code, we can see that the property changes are implemented via AWT. Why is this so?
As mentioned in Using Top-Level Containers,
Each program that uses Swing components has at least one top-level
container. This top-level container is the root of a containment
hierarchy — the hierarchy that contains all of the Swing components
that appear inside the top-level container.
java.awt.Container, an AWT Componenet, is that container.
Addendum: This overview suggests how pervasively the interface java.beans.PropertyChangeListener is used throughout AWT and Swing.
Related
I design a custom component (mainly override paintComponent for desiring appearance) and compile it then drag it to a JPanel in the Netbeans design mode.
It works correctly and the Netbeans designer renders it in time and correctly when changing the property of the component. But when I modify the custom component source code and recompile it, the Netbeans UI designer doesn't update the appearance of the component unless deleting it then dragging the recompiled component to the panel.
Is there a way to update the modified and recompiled components in Netbeans UI designer without deleting them?
If I wanted to scroll to a newly generated component after some work is done/outputted, how would I do that via Java? Or would I need to introduce additional functions with JS/CSS files into the build?
This should work:
UI.getCurrent().getPage().executeJs("arguments[0].scrollIntoView({behavior:'smooth'});", component));
Here component would just be the name of the target component, and the behavior of the scrolling would be smooth. There is also "auto" for the behavior but I prefer the former.
I found this line on the java docs tutorial site- "A Frame is a top-level window with a title and a border". Here, what is the meaning of "top-level window"?
A 'top-level window' or 'top level container' is something that can be shown on screen without having to add it to another component. We would start a GUI with a top level container, and then add panels and components to that TLC. E.G. of top level containers..
AWT - Frame, Window, Dialog ..
Swing - JFrame, JWindow, JDialog, JOptionPane ..
Java-FX - Stage (I have not used Java-FX much, so am unfamiliar with the other variants of TLCs, but see the Java-FX API docs for other examples).
See also this answer for many good reasons to abandon AWT components in favor of Swing. As to abandoning Swing for Java-FX, I'll be unwilling to do so until Java-FX is promoted to the Java API's Java docs, and makes it into the official Java Tutorial. Sun, then Oracle, has a bad habit of hyping many technologies only to later quietly drop support & development for them.
In GUI toolkits such as AWT, a top-level window is a window which is usually known to the OS (heavy-weight components).
Side note: AWT (and even Swing) is a pretty old technology. I recommend to use JavaFX where possible.
a window without a parent.
a window can have child windows alright and they have a parent then
Observe difference among these classes.
Frame is top level window because it has border and title. An instance
of frame can have a menubar. Without those it is mere is an instance
of java.awt.Window class.
Window class: It has neither border not title. Window class is not attached to nor embedded within another container.
Dialog: It has border and title. An instance of the Dialog class cannot exist without an associated instance of the Frame class.
Panel: just a generic container to hold components. Its instance provides a container to which to add components.
Note: Revert me back if further clarification is required.
I'm creating a user interface for a java standalone desktop application but the forms, text fields and tables I built using javax.swing and java.awt packages look quite dull. Are there any methods by which these components can be stylized so that they look more appealing (like those beautiful websites made with css and javascript) ?
You can set the background, border, foreground, etc of these components. Consult the API for useful functions.
Or you can change the look and feel of your entire program. Recommended reading: http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
You could use Look and Feel, there are libraries that set your all your components with a defined style.
See this link http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/nimbus.html
I am designing a eclipse plugin, where i use Components of Swing and JavaFx. In this I can apply CSS on JavaFX. But i could not apply CSS for Swing components. I was forced to use Swing component for some features of the plugin. So i would like to apply CSS for Swing components too. Is there any api that supports CSS on Swing component?
//This code applies css for javafx components
SwingJavaFxSample.class.getResource("samples.css").toExternalForm();
Please help me in applying css for Swing components too.
You can not use the JavaFX CSS support on Swing controls so to me the question makes no sense. Let me also say that using 3 UI-Technologies together is not really a good idea you'll run into many threading issues (SWT & FX share the same event thread whereas Swing is on another one), ... .
What is the reason you still need Swing? JavaFX can be embedded directly into SWT.