I am stuck trying to make the following kind of slide menu in Swing.
I have searched entire web but I didn't find any tutorial or maybe I missed that. Can you please suggest a solution or a tutorial? I don't need code but just the components to use.
This is very simple in Swing.
What you are looking for is a JSplitPane. You can start with it closed and it has arrows (or other symbols depending on your look and feel) that can be clicked on.
http://docs.oracle.com/javase/tutorial/uiswing/components/splitpane.html
Note: A slider is a very different component. (http://docs.oracle.com/javase/tutorial/uiswing/components/slider.html)
Edit: Based on your comment it sounds like actually are looking for an animated opening of the slider (which is hard to tell from a static image).
In that case this question is a duplicate, look here: Animation for divider movement in JSplitPane
Related
I posted a similar question a year ago, but it was not really well written and I didn't get an answer I could work with. Now I stand in front of the same problem. I got a JPanel (my content pane), where a MouseListener is implemented.
Everywhere I click, I get the exact coordinates of my mouse click. Except my JTextField components. When I click on those, the MouseEvent isn't even triggered. H
ow do I do this, so my mouse clicks on those will also call the mouse event?
Tried: setEnable(false) and setHighlighter(null)
Sorry thought I fixed the X/Y problem.
The X/Y problem simply means you are telling us what your attempted solution is without telling us what your requirement is. We can't suggest a different approach if we don't know what you are trying to do.
I want to open a menu,
Now we know what the requirement is.
The solution is to add the MouseListener to the text field, not the panel. If you have the same popup of the panel and the text field, then you still need to add the listener to both the panel and the text field.
You can do this in one of two ways:
Read the section from the Swing tutorial on Bringing up a Popup Menu for a working example.
Note the above tutorial is a little old, you can also check out the setComonentPopuMenu(...) method of the JComponent class. This approach will create the listener for you.
I'm not very experienced with Java Swing Layouts. I'd like to make a layout looking like the one in the picture. Is there any easy way to understand and create layouts?
There are tutorials on the oracle website and there are wysiwyg layout-building tools that show you interactively what you are building. One of them I have personally used in the past is the Window Builder you can get as an eclipse plugin but it is by no means the only one.
In the end though what it comes down to is experience. Fool around with them, try them out, get to know them. If you dont code with them yourself it is difficult to understand them properly.
Is there any easy way to understand and create layouts?
I cannot judge what others would find easy, but my approach to laying out containers is to look for sub-sections of the GUI that would be easily done with a particular layout, then working outwards from that.
For example, it seems a single row GridLayout might be well suited to displaying the top two text panes. Then the rest of the GUI can be created by placing the panel with the two text panes into the PAGE_START constraint of a BorderLayout, with the third text pane in the CENTER and the text field in the PAGE_END.
Done.
I know I can change panels by using card layout but while I was browsing I saw an effect where panels move from left or right to replace the current panel.
With Card Layout, changing panel is working but can't achieve a moving panel effect.
I don't know what it's called. I don't know if "dynamic" is the correct term for it.
So here's the link to help you guys understand my question better.
https://www.youtube.com/watch?v=0Y7cxgX4Suc
According to the description it's all done in Swing and no JavaFX.
I'd like to be able to show and hide (and therefore grow and shrink the jpanel as appropriate) in my swing application. I've seen something similar on websites that I imagine uses JS and JQuery.
What I'm after is the ability to click a button (that might say 'Advanced options') that then 'slowly' grows the panel and reveals (setVisible(true)) components.
Is this possible using Swing? I've tried looking round the web, and SO but I only seem to get JQuery questions, or unhelpful Java posts. This is the closest I've found.
Use a Swing Timer to animate your slide. For example, this link has code that places the components in a JLayeredPane and slides one component over the other, again using a Swing Timer: slide effect with JPanel.
Another useful effect is to fade out from one JPanel to another. For an example of this that uses a Swing Timer as well as a CardLayout, please check out this answer.
In C#, to make the tabs go from right to left, I set RightToLeft to Yes and RightToLeftFormat to true. How do I do the same thing in Java? How do I set a JTabbedPane's tabs to display from right to left? Please see the image link below to see what I mean by displaying tabs right to left.
http://lh4.ggpht.com/_1bcR6vegNNc/TPDRekNVqWI/AAAAAAAAAB8/TwCqgajEuoI/s640/AdminDashboard.jpg
I assume by "tabbed pane" you are referring to javax.swing.JTabbedPane.
To answer your question: AFAIK there is no easy way to do what you want. The BasicTabbedPaneUI(or the TabbedPaneUI which is defined by your application look and feel) which is responsible for painting the tab area of the tabbed pane would require some changes to be able to do what you need.
If you do not have the time to write your own UI, you could look for solutions in the web. I doubt that there would be a ready to use solution to your question though, but then again, who knows?
Hope this helps you a bit.
Then i'm refer from "How to Use Tabbed Panes" to create a new project based by JTabbedPane component...
It's enough to use "setComponentOrientation" method to change orentation of JTabbedPane.
link text