I want to render Swing over top of LWJGL. It's my understanding that it doesn't work because LWJGL is heavy and most swing components are light. I'm guessing it's an option to put all my Swing stuff inside heavy components so they can render on top of it, in the same way a JPopupMenu does. Is there something that is basically a heavy version of JPanel? Like JInternalFrame, but without the top bar, close button, etc, just a simple rectangle? If not, is extending and disabling all the features of a JInternalFrame the best choice? (I'm assuming that is doable).
Additional related question: I read somewhere heavy components can't be transparent, does that just mean no translucency? Or does it mean I can't make a doughnut shaped heavy component?
Related
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.
I'm using a AWT PopupMenu on a frame that constantly repaints (it's a game), but whenever the PopupMenu shows, the parent frame freezes. Is there a way to disable this?
I assume the rest of the application is in made in Swing and you are using the AWT popmenu in combination with Swing components.
I've had my fair share of AWT PopMenu problems. Do you need to show the Popmenu outside the bounds of your application ? If you only need to be able to show it inside your application (JFrame) you are probably beter off with just putting a JComponent on top of all your other panels (with a JLayredPane) and draw your own pop menu there.
Even easier is to use JLayer in Java 7 for the same effect (or JXLayer if your not on Java 7 but on Java 5 or 6).
The above method is also way more powerful then the AWT popmenu because you control the drawing. So for example making it translucent or giving it round edges becomes a breeze.
I'm programming this level creator for a game me and a few of my friends are doing but as of right now the GUI is using a null layout, which I don't want to. It works fine for now, but I'm still against it and I know everyone else also encourages you to ALWAYS use a LayoutManager. I'm not really willing to compromise the design as it is right now, so I pretty much want to know if there's a LayoutManager that allows me to create a GUI that looks like this:
IT HAS TO BE IN THE STANDARD JAVA API! :)
This looks like a good job for a BorderLayout. Put the buttons inside a nested container as the NORTH element. Add the JScrollPane as the CENTER component. The grid itself looks like it is a good candidate for a GridBagLayout or perhaps a GridLayout.
Short answer, yes: GridBagLayout. But that'll be a pain to work out and debug.
Long answer: It looks to me like you could do this best with a BorderLayout, a JPanel for the JButtons, and a JTable with custom TableCellRenderers and TableCellEditors.
Check the excellent documentation available for Java by Sun itself:
http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
Can you spot the GridLayout and GridBagLayout? If you put it into a scrollable container, that should do the trick.
Use GroupLayout for the overall panel and a custom paint method for the map.
I don't think many people here would recommend GroupLayout because it's more complicated than the other layout managers. I like it because it produces great scalable results, so I invested the time in understanding it. Now, I hardly use anything else - especially for user interaction panels with buttons and text fields.
For the map, though, I would create a custom MapPanel and overwrite paintComponent(). Sure you have to write your own custom scrolling algorithm, but I think that's a small benefit for not having to deal with scroll bars. You could make it so someone could just drag the mouse around and move the map. Use the mouse wheel to zoom, and make the interface very intuituve. If you want to paint scrollbars, you can do that too.
I've built several interfaces using models like this. I've built several maps for games using this model, as well as a financial market charting package. It makes it very easy to add custom functionality to do some great things that would be a nightmare to try to do in a JTable.
I already designed many JPanel's for my application in Netbeans now i want to ..
Add background images to all jpanel's in which i had some jcomponents already.
And i want it to do it for jdialog too.
I need to design a JMenu with images and menu name.
But already i saw many examples for background images in that they are adding there components through coding im doing it in Netbeans.Is it possible to set it for the main JFrame then i can leave the jpanel's.
If you use netbeans background image can be added using a simple method. I don't know whether it is a good practice, but it is really easy. See this video.
is it possible using swing, to build a GUI whose elements, when the GUI is resized, keep te proportion between themself? Or i should fire a "resize every GUI component" function when the resize event occurs?
I'm using Netbeans 6.9
Long ago, there was a very interesting article series on JavaWorld about "transmogrifying widgets" by Allen Hollub. This serie explain how, using different widgets to sho the same information, a calcoulator can have different styles when viewed with different dimensions.
However, for a far simpler (but far less powerful) approach, you should take an in-depth look to GridBagLayout and the (now famous) GBC class. This will give you a fast, and quite elegant, method to resize your whole UI with interesting resizing behaviours (oh and don't forget the associated tutorial).
I think that using traditional layout techniques is the best way to go - you generally want to choose which components resize and how they do it. However, if you really want a proportional resize then have a look at this answer:
java swing resize