What problems might arise when adding JComponents to a component - java

I am making some changes to an existing application whoose screens have been implemented by using awt components. Using swing in the new elements will make life easier but i know that there are some problems of mixing swing and awt components.
What i would like to know is:
Prior to java 6 what problems might arise when someone adds swing components to an awt container?
(My appliation has custom mdi which every window is an awt panel. What I would realy like to do is use the same awt panel as my window and implement everything inside of it with swing using java 1.5)
In some forums people says that after java6u? some of the problems of mixing awt and swing components how been fixed. is there any problem still exists that you know of ?

See Mixing Heavyweight and Lightweight Components for answers to both your questions.
Here is an example of the problem.

Related

Mixing Swing and JavaFX in a Java desktop chat application

I know that there are already some question about this, but I can't find my way!
I want to implement a desktop chat application with java which is able to send text,image, video, etc.
Now I am using swing component for my chat conversation window.
I create a JFrame and add JTabbedPane to it inorder to have tab for each new conversation.
for creating each tab I act as follow :
create JPanel (I add this to my JTabbedPane as tab)
newtab = new JPanel();
newtab.setLayout(new BoxLayout(newtab, BoxLayout.PAGE_AXIS));
create JTextPane for display's part of the chat (to have style for conversation like android application such as viber, ....)
I want to be able for following styling:
diffrent alignment
change font, color
insert JComponent (to show other type of messages )
setborder of each message round (I don't want the squre one)
...
context = new StyleContext();
kit = new HTMLEditorKit();
chatPane = new JTextPane();
chatPane.setEditable(false);
chatPane.setContentType("text/html");
chatPane.setEditorKit(kit);
chatPane.setText("");
doc = (HTMLDocument) chatPane.getStyledDocument();
CSS(); // it is for adding ccs style to stylesheet of document
JScrollPane scroll = new JScrollPane(chatPane);
newtab.add(scroll , BorderLayout.CENTER);
My problem is to set perfect stying to my display part, since javax.swing.text.html.CSS provides HTML 3.2 support, so the CSS properties that are supported are limited!
while searching on Internet I find JavaFX, but I don't know is it good to use JavaFX and swing together or even is it possible?!
also which layout manager is better for the JPanel (newtab) to have my JTextPane with scroll.
As its already been said, it is possible to mix Swing and JavaFX especially since Java 8 you can do it both ways:
Embed Swing Components in JavaFX with SwingNode
Embed JavaFX Components in Swing with JFXPanel
Recently we had to make the same decision. We had an application and wanted to migrate to JavaFX to get a more modern design and to make use of all the introduced language features like PropertiesBindings etc., which is nicely supported by JavaFX Components.
So first we tried to embed JavaFX in Swing. All new components were embedded with the help of JFXPanel. It was really easy, but from time to time we had some rendering issues which got more and more annoying. "Unfortunatly" we got used to the new JavaFX API, which is why we deceided redesigning our appliction to make it a JavaFX application with some Swing Parts in it, which was possible, when Java 8 was released, since we didn`t wonna waste time on fixing thoses kind of rendering issues. The redesign was actually some work since some concepts are just different. Benefitting from the new API caused some refactorings, we didnt really wonna do in first place.
But then again mixing Swing and JavaFX got a bit fuzzy, and the look and feel of the application didnt really feel convincing, so then we finally removed all Swing Parts and replaced them by JavaFX Components. So far we don`t regret that step, but it was more work then we expected it to be, eventhough we already used patterns like MVP, where only Views had to be refactored, since presenters were (mostly) free from UI stuff (which was really an interesting process, were we learned a lot about MVP and designing an application).
So in conclusion I just can suggest to create a list of views you have and think of all the components you would need and try to find the corresponding components in JavaFX. Make small examples for the most complex components to see if they fullfill all your usecases. If that is the case and you still have enough time to switch to JavaFX I personally would go for a pure JavaFX approach, because of the experiences I made with mixing JavaFX/Swing, especially since your UI design seems to be in an early state. In the end it is just a question of time you have available for your project and if you are really up to learn about the new concepts and components of JavaFX.
Concerning the JavaFX CSS Support, you find a reference here.
It IS possible to mix JavaFX and Swing. But I have no experience in it. I just did a little FX-UI for a small project which was pretty nice. Especially the CSS-Feature is great.
According to mixing, I just recently found a blog which discouraged mixing both technologies: http://dlemmermann.wordpress.com/2014/07/17/javafx-tip-9-do-not-mix-swing-javafx/
Maybe this gives you a little help.
Recently I was asked same question.
About one month ago I started new project with my team. We use Java 8.0 + JavaFX 2.2.
What problems did I find in JavaFX?
It's new technology, so many issues still not answered. And you must look for it own.
No tray supporting, so you must use java.awt.SystemTray.
Also I found one problem in the design.
For example you want to make beautiful list with cells which contains label which stuck to left side and checkbox about right side. But there is no good way to do it and you have to calculate length of cells and etc..
But JavaFX provide great opportunities for cutomizing GUI. And you can incapsulate your design in jxml file. It's very convient, because it even more separate code from design.
About mixing I think that if platform allows it than you have to use a solution that provided a platform.
And I think that the decision to use JavaFX correct, if only because it is a relatively new technology, developed by Oracle and it probably will soon replace the swing.

How to create the windows 8 FLAT native look in Java Swing programming?

I am creating a java swing application and I am badly need to get the flat GUI look like in windows 8 to my swing application. But I couldn't find it yet. Can you help me?
You can PROBABLY use the default look and feel of swing apps, undecorate everything, and for those icons; I would use buttons with internal panels, images, labels, etc. To get the scroll functionality you should use mouse listeners to detect scrolling and slide the ui accordingly.

CSS on Java Swing from Java Code

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.

Regarding swing containers

I was doing a research, I have the below application in that we have the following swing layout..
Now the thing is that this same ting I want to develop I was using swing designer of google framework ..
Please advise me what container layout and extras other things do I need t build this same forat through swing designer and I aslo later want to customize it.
As I understand, your problem is resizing two buttons equally? Well, I'd use Mig Layout, create two columns, that will scale 50% each.

Reduce overlapping of JWebBrowser in Swing

I am developing application based on Swing.
My problem is I use JWebBrowser and I put one in a scrollable panel. When I scroll down the panel the web browser overlaps the panel/frame of the application.
What can I do so the browser does not overlap the panel?
I don't see an answer here, so as someone who has been down this bumpy road, I can sympathize with these issues and would like provide some guidance.
First of all, the JWebBrowser is an AWT heavyweight component, and does not play nicely in Swing (since it uses lightweight components) without some intervention.
Instantiate JWebBrowser like this for the first step of friendly Swing integration:
new JWebBrowser(NSComponentOptions.destroyOnFinalization(),
NSComponentOptions.constrainVisibility(),
NSComponentOptions.proxyComponentHierarchy())
That instantiation alone should prevent the browser from overlapping the Swing lightweight components, however, it will not work as you would expect with transparencies or layers unless you do some additional steps.
So, during construction, call these:
webBrowser.setDoubleBuffered(true);
webBrowser.getNativeComponent().createBackBuffer();
And then, right before the web browser is to be used with any kind of transparency or layers, call these:
rects[0] = webBrowser.getBounds();
webBrowser.getNativeComponent().updateBackBuffer(rects);
Those calls will repaint the backbuffer right before the component is to be used and so when being used, it will be displayed with that most recent backbuffer and will look pretty much like a regular Swing component at that point.
There are some nuances with all of this, but that's the basics and should be enough to get anyone started with it.

Categories

Resources