• Post Reply Bookmark Topic Watch Topic
  • New Topic

jFrame to use css?

 
Dj Galla
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Net Beans, I created a jFrame form based on a simple app that I put together (you can see the original app here). You enter a number, and it returns an element of an array.  The form works, but I want to streamline the app.

First, when the output is set back to the form, I want that output to be able to use CSS styling (i.e. paragraph tags, with margins ... h3 tag formatting).
I also want the output to show a scroll bar, if the content that is outputed is too long.
And finally, the jFrame doesn't support a background image. I found a solution that uses an absolute positioned jLabel, and am able to use a background there. But the if the jlabel is larger than the image, the background color doesn't show up (even when I set it to a specific color).

See the image below, that shows the jFrame, and explains the issue...


Below is the code (Note: most of the code was generated from NetBeans when I created the jFrame form). The code I played with were lines 79-94. There is another class (in a separate file), that defines that Paragraphs class, and defines the getPara method (not needed for what I need to do).
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dj Galla wrote:First, when the output is set back to the form, I want that output to be able to use CSS styling (i.e. paragraph tags, with margins ... h3 tag formatting).
I also want the output to show a scroll bar, if the content that is outputed is too long.
And finally, the jFrame doesn't support a background image. I found a solution that uses an absolute positioned jLabel, and am able to use a background there. But the if the jlabel is larger than the image, the background color doesn't show up (even when I set it to a specific color).


Nothing in Swing supports the use of CSS to style the GUI. I know that JavaFX does support CSS, so maybe you might consider rewriting your app in JavaFX.

As for your other questions, it looks like you're expecting the JFrame to do everything.

If you want a background image, the way to do that is to use a JPanel to contain everything and then make it so that the JPanel has a background image. Here's a link to our wiki which describes how to do that: Background Image On JPanel.

And if you want a scroll bar, the most practical way to do that is to wrap your text component in a JScrollPane. It's possible that you could wrap your JPanel in a JScrollPane and have the whole thing scroll, not just the text component, but that would be more complicated. I'm sure it could be done but I'd suggest doing the simple thing first.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!