Larger Scrollbars - java

Is it possible to enlarge scrollbars of SWT controls?
I would like to change the size of all scrollbars that appear within SWT screens in my application. This includes those that appear on tables, scrolled composites, text fields, etc. Can these be modified graphically?
Before:
After:

No. The scrollbar is handled by the OS, i.e. the OS decides how the scrollbar looks. You could draw a scrollbar yourself and hide the system one. That would involve a huge amount of work though.
You can read this tutorial if you want to know more about drawing stuff in SWT:
Graphics Context - Quick on the draw

Related

Java Swings Auto-Resize Pictures

I'm doing this project using Swing.
To add a more welcoming feel to the UI, I'm also adding a few Photoshopped images as the background.Here's where the problem begins...
I want the images to automatically resize themselves once the size of the window is increased or decreased, how can I make this happen ?
One way is to override the paintComponent(...) method of a JPanel to paint the image using the drawImage(....) method.
Another option is use a JLabel with an Icon as the background for the frame. Then you can use the Stretch Icon which will automatically scale based on the space available to the label. This is the most flexible solution since the StretchIcon can be used on any component that supports icons.
You can also check out the Background Panel which allows you to display an image. You can display the image at its actual size, scaled or tiled.

Java Swing - Scaling UI to fit window resolution

I have made a program that uses null, border, card and some my custom layouts. The window of the program is set to resizable:false. Now I wan't to make full screen mode for my program but the problem is that GUI looks ugly if the size of the screen isn't the one I set. I could implement some kind of scale factor for all the components but the problem is that I have over 2000 components in over 50 classes.
Is there an option to resize whole swing UI for defined factor? That means that the image rendered as UI and all mouse events aswell would be resized.
You should probably try to rely on your layout managers. Try to figure out specifically which layouts aren't resizing the way you want, and focus on correcting their behavior instead of trying to manage everything from the top down.
Alternatively, you could keep the size ratio by adding black bars to the top and bottom or left and right of the window when it's in full screen mode. You'll probably still have to play with some of the layouts to get them perfect though.
Having 2000 different components sounds like a usability nightmare, but that's a different issue.

Java application automatically resize to fit screen resolution

The touch-screen application I am developing will be used on different screen resolutions. I never had to worry about this before, but now I do. I am wondering how can I design the GUIs so that EVERY object on the GUI resizes proportionally to fit the screen resolution? Can you refer me to a good tutorial page? I am designing the application using the NetBeans and the Swing framework. Thank you
I am wondering how can I design the GUIs so that EVERY object on the GUI resizes proportionally to fit the screen resolution?
not easy job you have to test all possible pixels ratio that exist (by default is possible to change and set various pixels ratio on todays fullHD screen) with lot of fails
this is reason why LayoutManagers exist,
I'd suggest to use NestedLayout
sure there are custom LayoutManagers, for example by using MigLayout (something betweens GridBagLayout and SpringLayout) is possible to put all JComponents to the container from one place, but again I'd be suggest use NestedLayout instead
you have to set (internally) minimum screenSize for displaying contents in the JScrollPane, for example screen with resolutions less than 1024 x 600 will have the content scrollable, otherwise let's this job for LayoutManagers,
this idea required model JFrame ---> JScrollPane ---> JPanel (father panel) in all cases, JScrollPane will protect your GUI against small (and dual too) screen resolutions
you have to look at FontMetrics for Font, because you need in/decrease Font size for various pixel ratios continiously with JComponents size on the screen
same with Icons if exist, prepare that before in some of Graphics SW's, not resize on runtime
my view ---> any Framework based on AWT/Swing isn't advantage for job this nature,

Resizing a JPanel with resampling to preserve content

Give that I have written a JPanel with many different components on it, is there a way to apply an overall "dilate" ability on the panel so that everything in it stretches proportionally when I resize my window?
That is, if I manually resize my window to be 1/4 the size, everything in the panel should also shrink by 1/4 so the new panel is just a dilation of the first. Given that I have not designed the individual components inside to do this (there are many) is there any easy way to make the panel behave this way?
UPDATE: In order to be more clear on the solution I need, I will describe the panel contents:
The panel is a "game" of sorts, with a single null-layout and dozens of ImageIcons flying around the screen at any time. The ImageIcons are preloaded PNG files, which already have a permanent size. Of course, I could manually resize each ImageIcon and reposition them relative to window size, but that would involve recoding many components.
There are no buttons or text to worry about, so what I'm really looking for is some kind of "postprocessed" resize where the panel simply shrinks whatever's rendered by some porportion (think of resizing an image in Photoshop).
One option is of course to give up swing all together and use some 3rd party widget component library which draws itself using any Graphics. Then you can either draw the widgets on the image and resize the image, or, better yet, apply a transform to the graphics object you pass to the library.
If you do want to stick with swing there is the SwingUtilities.paintComponent method, which you could use to paint the Panel onto a BufferedImage which you could then resize. (I've used this myself to do some nice transitions between "views" in a game.)
The problem is of course that you somehow need to translate the user input accordingly. I have no solution for this right now, but the above perhaps helps you in some way.
You can try to override paintChildren() method of the panel and scale graphics to achieve desired visible size.
You could try J(X)Layer, see http://www.pbjar.org/blogs/jxlayer/jxlayer40/
Using layout managers instead of absolute positioning of the widgets will give you this behaviour. See the oracle tutorials: Using Layout Managers.
Do you really want fonts to resize on resize events? I don't know a layout manager which will do that for you.

'image stretch' proxy for slow Swing component?

I have an application that displays plots using JFreeChart. As it happens, these plots are big and JFreeChart is not terribly fast, resulting in atrocious redraw times, particularly when resizing the plot.
What I am after is a way to stretch an image representing the plot while resizing (a bit like the iPhone will present a screenshot of a stopped application while it gets started again), and perform a full redraw only after the user has released the mouse (i.e. once the final size of the plot is known).
The interaction features of the chart sould stay intact (when not resizing, obviously).
Is there a generic solution / Swing wrapper for this? (there is no reason why it should be JFreeChart-specific).
Cheers
No concrete answer, just a possible strategy
on starting the resize, paint the plot into a BufferedImage and show and resize that image instead of the plot
on stopping resize remove the image and show the plot again
in JDK 7, you can use a JLayer for the image/manipulation.
Edit
Alternatively (for JLayer), you could use a CardLayout: showing one card with the image while resizing and the another card with the plot while not resizing. SwingX ImagePainter can do the image scaling during the resize

Categories