Can I disable the minimize button in JFrame?
I have already tried setUndecorated() and setResizable() but both did not work.
I'm trying to add images to a panel at a random location (which works) but when the JFrame is minimized by clicking at the minimize button (not when frame minimizes by clicking the background window) images assemble at the top in a row.
Can someone help?
Thanks!
If you also want to disable the maximize button then you can use a JDialog instead of a JFrame... as far as I know you cannot disable the minimize button in a JFrame. JDialog only has a close button. Hope this helps
i m trying to add imags to a panel at
a random location which i m able to
do) bt wen frame is minimized by
clicking at the minimize button (not
wen frame minimizes by clicking at the
background window) images assemble at
the top in a row.
Well, it sounds like you are adding labels to a panel and using the setLocation() method to position the labels.
The problem is that by default a JPanel uses a FlowLayout so whenever you do anything to the frame like minimize, maximize, iconify or resize the frame the layout manger is invoked and the labels are arranged according the the rules of the layout manager.
If your requirement is to have random positioning, then you need to use a "null layout".
Read the section from the Swing tutorial that explains how Absolute Positioning works for more information and a working example.
Use JDialog instead of JFrame it has only the Close button on the top.
Related
I want to make a some kind of modern GUI that has tabs on left, like shown on this picture:
Any ideas how could I make panels switch between while not disposing data that's written/set, for example into text fields, text area, check boxs, scroll bars and etc.?
I was thinking about just removing old one panel and adding another panel, but when I click on panel I visited before controls data will have been reset, and I think it would flicker.
Thanks to Frakcool:
Use a CardLayout for switching panels
I don't know if this is helpful, but you could try this;
Make a JTabbedPane, add it to the JFrame's contentPane.
add JPanels to the tabs.
then make sure that the tabs are aligned left and vertical by doing the following:
tabbedPane.setTabPlacement(JTabbedPane.LEFT);
and then, you can even do this:
JTabbedPane .setTabComponentAt(1, new WebVerticalLabel("Title1"));
to make the label text displayed vertical.
I hope this helps you,
Lenard
Can I place an image outside JFrame?
I am developing an app, and I wanted to make the Gui good looking and some part of the buttons should go outside. Is there a way to do this?
Yes, but it's not going to be easy, as you going to constantly need to monitor the position of the parent frame in order to maintain the position of the child window.
Essentially, what you can do is create a second, undecorated and transparent window. You would need to align and size the window next to the parent window.
On to this child window, you would need to then add a transparent component which would act as your primary container.
Take a look at How to Create Translucent and Shaped Windows for more details
For example:
How to draw images on transparent window?
How to make a transparent JFrame but keep everything else the same?
Creating a JFrame you can click through
No; the Swing framework doesn't handle painting outside the root component.
So basically, I am trying to get a JPanel window which will display all components inside dynamically. In other words, which will re-size the window, and display to fit its content.
I have been able to do it with help of JFrame and its pack() method which : "causes this Window to be sized to fit the preferred size and layouts of its subcomponents".
In my situation, I dont want to use JFrame because it will require much effort to make all changes.
Right now, I am able to make it work but only with the help of jscroll inside which wraps the text and or any new lines, so the window size is more static. So my JPanel is extending a TopComponent and am able to display it with:
jpanel.open();
jpanel.requestActive();
So the question is how to resize a window to fit its content upon actions in that window.
The JPanel has to be added to a Window in order to make sense. So I suggest you use layout managers correctly and you will get to a decent user interface.
When you add/remove components from a visible panel you need to use:
panel.revalidate();
panel.repaint();
Then the layout manager will lay out the components again.
I search for a method, which gets called if the jpanel is shown on the display, because i have to fetch the real size of the panel.
Any suggestions?
Have you tried adding a ComponentListener to the JPanel? That would be where I would start with my code in the componentShown(...) method. For this to work, I think that you must call setVisible(true) on the JPanel after adding it to the display.
The other option is to simply query its size after calling pack(), or setVisible(true) on your GUI.
Edit
You state:
I added the panel to the gui designer.. when the window pops up, i wanna now the real size of the jpanel, because it can change it.
If you want to know the size of a component held by a window "when the window pops up", then add a WindowListener to the window and check the size of the component from the windowOpened(...) method.
Edit 2
Then you state:
after i have the real size, i add some subpanels, in relation to the size of this panel. so e.g. size/6 & the subpanel has now the size-height of size/6.
One Solution: Better not to set the sizes of anything but instead to use the right combination of layout managers and then let them set the proper sizes based on their rules.
Set the visibility using function setVisible(true);
I'm building application in NetBeans 7.1, and I'm new in it. I have made one JFrame and two JPanel's, I want to switch between JPanel's on button click(I have buttons in those panels of course). The thing is I made those JFrame and JPanel's with NetBeans IDE and I don't have idea how to switch between JPanel's inside one JFrame. I tried with SetVisible(true); but that only opens new JFrame which I don't want.
Thank you all in advance.
If you want to swap between panels in the frame, then you probably want a JCardLayout.
You would set the layout manager to JCardLayout of the frame, and then add the two panels to the frame. Then, when the button is pressed, you can use 'first(), last(), next(), previous() or show()` to move between the panels.
If you want your flipper button to be visible all the time, use some other layout on the frame, and put the button to the frame (in whatever appropriate fashion), and then create another panel with a card layout, add the two panels with controls to the card layout panel, and then add the card layout panel to the frame.