Im making a Java application which views a set of images within a timeline. My Idea was to use a JScrollPane with the set of all images set out in a grid-layout, but rather than scrolling the pane using the traditional scroll bars, I wanted to use something like a JSlider.
The purpose of this is to give the user more control and idea of the time at which the subset of images is shown and to give greater effect of a timeline. I have produced a simple visual example of my idea below:
I wondered whether this was even possible as I have not seen any similar examples after extensive research. Any help with any possible solutions is greatly appreciated.
Many thanks.
Some ideas: Put the images into a JPanel and this JPanel into a JScrollPane without scroll bars at all. Then sync the slider (ChangeListener) with the JViewPort.
Or (simpler) use the horizontal scroll bar as the slider and custom a JScrollBar with the labels.
Related
I was looking for a way to rotate JLabel vertically and I found that several posts related to this topic suggest to use Graphics2d. But, in this way, the size of my JLabel is inconsistent (widht & height inverted).
I found also that another user, here, suggested this code.
Actually, the code works, but there are no indications about how to align the text of the JLabel, and this is what i get:
Can anyone help with any of the two methods (controlling size in method one or 1 aligning text in method 2)?
Thank you very much in advance.
One way is to create an Icon of the text and rotate the Icon then add the Icon to the label. Then the size of the label will be calculated normally.
Check out the Rotated Icon class for an example of this approach. You will also need the TextIcon class.
These two classes may seem like extra work, but it is an example of how to create reusable classes to you don't do custom painting all the time.
For a project I have an almost working code, but I do not have the GUI. I want to make a screen that consists of clickable labels and has the following design:
I was thinking about first making the middle GridBagLayout with with a dimension of 6 by 2. Then 'wrapping' that up and adding the two buttons to the side, and then 'wrapping' that and adding the two buttons below.
I am inexperienced with Swing, and I have no idea how to start. I hope someone can give me some hints in the right direction.
Several approaches to a very similar layout using GridBagLayout and/or nesting are shown here. Consider using JButton for each clickable area, rather than JLabel. If you go with a nested layout,
Use BorderLayout for the enclosing panel.
Add buttons to EAST and WEST for the leftmost and rightmost areas.
Add a GridLayout(1, 2) of buttons to SOUTH for the bottom row.
Add a GridLayout(2, 6) of buttons to CENTER for the central twelve areas.
Addendum: A critical issue will be what you want the resize behavior to be.
as said in the comments above you could (should ?) use the WYSIWYG Window Builder plugin available for Eclipse; it's simple to use.
However, that doesn't answer your question, so to do so, here is how I would structure the UI if I were to make one like that :
http://www.hostingpics.net/viewer.php?id=902716gZHkK26.jpg
I basically use BoxLayout because that's the one I'm most familiar with. Every Rectangle is a JPanel. I think the image is pretty self eplanatory.
I am Working with Swing in java and I'm making a little tool to compare 2 Files.
The Comparing works, the differences are marked in Red.
So I tough that I could make a kind of Bar next to the ScrollBar to show where I have to Scroll to find de differences in my text. Something like in Eclipse to show where are Errors, Warnings and TODOs
Another possibility coulb be to put the marks into the ScrollBar.
Is that Possible and if Yes, how can I code this? Thank you for your help
Place your scroll pane in a JPanel with BorderLayout. Add one more JPanel's extension to show all the marks and place it to the east (or west). Place the marks on the panel and add a MouseListener to process clicks and scroll to desired positions.
Or you can use custom row/column header. Like this
http://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html
I’m making a sample application that uses MigLayout in a very cool way. Unfortunately after reading through the quickstart and the whitepaper I still have questions and can’t do my desired layout. The sample application lets you add/remove games which are basically an Info Panel + JLabel. The layout should have two rows, one for the info panel and the other one to the JLabel.
Layout:
Row 1 (Info Panel) : [grow][grow][grow][grow]
Row 2 (JLabels) : [grow][grow][grow][grow][/list]
Here is an image so you guys can see clearly:
So when I add a Game the layout should shrink the other to fit, like on this image:
And when I delete the layout should grow the remaining one:
But it’s not working with the given layout info, can you guys give me a hand? Also the shrinking JLabel should be handed by me, since it can’t resize automatically???
Sounds like a simple GridLayout will do the trick.
Yes, you will need to do custom paint to resize the image as the space available to it changes. This means you will probably need to use a JPanel and draw the image manually so you can scale the image on the fly.
Been developing a game for a while, and currently re working the GUI, or at least trying to. Had the massive problem of not being able to resize the frame (without issues), as I didn't understand layout managers very well. A few projects later, and time to come back and do some more on the game, and I hit a problem...
The basic layout of the main frame is, mainPane, containing one gameScrollPane and one controlPanel. The scroll pane is a scroll pane, and the control panel a normal panel. The scroll pane contains the main game panel.
As I wanted the scroll pane to take up most of the screen, with the control panel taking up a small lower area, much the same as many Sim like games, so chose the Border layout for the mainPane. I added the scroll pane and set the constraints CENTER and the control panel added and constriants SOUTH. This didn't show the scroll pane, so I played around trying different constraints, and it seems that only when I set the scroll pane constraint to North, does it display at all.
To demonstrate this, I have created a quick video...
http://screenjel.ly/q5RjczwZjH8
As you can see, when I change the value of NORTH to CENTER and re run, it's like its not there!
Bonus points for anyone who can see a clear second problem which I may start another question for after this issue is solved!
I thank you for your time to read this.
Thanks in advance for any ideas or thoughts :)
Rel
If you'd posted some code to start with then you might have gotten a really quick answer. Luckily, you posted a link in the comments to the other response.
The setContentPane() stuff is weird, especially after doing some things to it that will then get wiped out. However, that's not your problem.
The issue is that you are adding levelMaker and personMover right to mainPane without any constraints. These will then be blowing away anything you set for CENTER... in this case the previously set gameScrollPane.
That's why you see it for NORTH and not for CENTER.
I can't get the video to show. It's been buffering for ages.
My guess would be that the scrollpane is in fact filling the center; it's just your game panel that's not being shown.
Your game panel needs to return reasonable values for getPreferredSize().
Update
Another thing you may want to do is have your game panel implement the Scrollable interface. You can then override getScrollableTracksViewportWidth and ...height to return true so your panel will be forced to the scrollpane's dimensions.