The knob of the JSlider originally has only 1 degree of freedom (it translates on the track either horizontally or vertically). I want to add a 2nd degree of freedom to the knob and manually rotate it. In other words, I want to be able to move the knob left and right AND rotate it. Both of these movements should be able to be set by either dragging the mouse in a linear or rotational direction. I havent seen code for this and was wondering how I could go about this.
I'd extend BasicSliderUI and override the paintThumb method so that you can paint your thumb at an arbitrary rotation, either by applying a rotation transform to the thumb image, or by manually drawing the thumb rotated. Then apply this UI to your JSlider.
To control the rotation with the mouse and keyboard, it may be easiest to add a MouseWheelListener to the JSlider so that you control thumb rotation with the mouse wheel.
Related
I am trying to implement the panning. I've a subScene with perspective camera and a Box inside it. I am able to pan the box relative to the camera (So camera is fixed and the box moves left right-left-top-down). How can I achieve panning by not moving the box relative to the camera. Is there any way to move the camera inside the subScene(Usually its position is fixed).
The problem in my current approach is that when I pan the box to left, its right face is revealed more because of the perspective. It seems like the box rotates a little bit on pan. I want to remove this slight rotation effect on panning for which I need to pan the box and camera simultaneously in same direction (without any relative movement between them). But I am not able to figure out how to move the camera as the camera position is fixed with respect to the subScene.
Thanks.
I am attempting to recreate Wheel of Fortune in Java. What I have been thinking about doing is creating a wheel, and rotating the image and randomly stopping. But, I don't know how to rotate a JLabel. I am using NetBeans JFrame creator.
I can't really provide code, as this is just a concept in my head right now. I am planning to set the JLabel's icon to the wheel. I need to be able to rotate a JLabel at a button press, and stop at random. It then, needs to read the rotation value of the JLabel, so it can read the amount of points you win. Is this possible?
Yes, I have researched. All the other rotating JLabel forums do not show how to read the rotation value.
I am a beginner in Java. Any help is appreciated! :)
I am planning to set the JLabel's icon to the wheel. I need to be able to rotate a JLabel at a button press
Don't rotate the label, instead you can just rotate the Icon.
Check out Rotated Icon. You just specify the angle of rotation and it will paint the Icon rotated. You can use the getDegrees() method to know the current rotation at any time.
I write simple game with libGdx. I have a hero, which always is in screen center and I must move my background sprite (or region?) to make move illusion. But my background sprite isn't infinity.
How can I create illusion of seamless infinity world?
Of course I can add several background sprites to try to cover all empty space of screen. But I must to draw out of the sceen a lot of all another objects: Houses, monsters, others heroes, etc. So I have a second question:
When I try to draw other object (a lot of objects!) out of the screen, how badly it affects memory? How to draw it correctly?
I know that OrthographicCamera in libgdx draw only viewportWidth-viewportHeight area. If it's right, then I must to move my camera and all my sprites too. I think it's not correctly.
How can I render infinity world in libgdx with OrthographicCamera?
How can I create illusion of seamless infinity world?
Create a tile background. Tile background means that if it was besides or top or bottom of itself, the edges of sticking line will not be visible to viewer.
To do this open your background image in photoshop and go to Filters > Other > Offset.
Set the offset filter to offset the background to center then try using photoshop tools to hide the edges (the + shape in image). Now again go to offset and return to 0, 0 and save your background.
When I try to draw other object (a lot of objects!) out of the screen,
how badly it affects memory? How to draw it correctly?
I have checked this and that was not much fps loosing on my test. So don't worry about it.
How can I render infinity world in libgdx with OrthographicCamera?
Move camera where-ever you want any x, y. Every time see where is camera and calculate needing tile backgrounds to draw (for example every time draw 3x3=9 backgrounds sticking together).
I have a JPanel with an vector image that the user can zoom and pan on. Overlaying this image is a (transparent) JComponent, which I allow the user to annotate the underlying image. This works great at full scale, but If I zoom in, using AffineTransform, the overlaying coordinates are affected also. So, If a user draws a box on the image the box is scaled also.
Any suggestions on how to decouple this behaviour? So that the JComponent is not affected by the JPanel's AffineTransform?
Typically, you need both a forward and inverse transform to translate between the two co-ordinate systems. In this example, the scaling equations are explicit; in this alternate approach, a second AffineTransform is used.
I am working on a project in which I have a background image with specific points of interest. Each of these specific points will have a custom button class overlaid on it so that when I click the point, I'm actually clicking the button. However, I would like to be able to rotate the background image and have the buttons rotate with the image so that the custom buttons are still overlaid on the specific points. Any tips as to how I should go about doing this?
Are you actually wanting to rotate 4 different images and move them around the square, but always keeping them upright? Or are you rotating a single image so that after one button click the single image is on its side? If the former, then that can be easily done by using a container (a JPanel) that uses BorderLayout, and having four JPanels with background images and JButtons held in the container JPanel at the four compass points of the BorderLayout: BorderLayout.EAST, BorderLayout.WEST, BorderLayout.NORTH, and BorderLayout.SOUTH (although Java gurus prefer you use the newer constants, i.e., BorderLayout.PAGE_START). Then when a button is pressed, remove components and re-add but in a rotated order.
If you want to do the latter, then things get a bit trickier in that you'll likely need to use AffineTransforms, rotate instance to rotate the container, and you'll need to perform the same transformation on the point of the mouse press/click/release, so that the rotated buttons receive correct clicks. If the container is not square, things get even trickier still.