I'm using code:
main.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("4.jpg")).getScaledInstance(main.getContentPane().getWidth(), main.getContentPane().getHeight(), Image.SCALE_SMOOTH))));
to set the image.problem is,it's not on the full frame
and having 1 more problem when I'm designing GUI in the NetBeans IDE,the picture is overlapping the components.
plz suggest some solution.
You need to use layout manager. Without layout manager it will be difficult to resize components manually. Check these links Resize the components of the frame in full-screen mode & Visual Guide to Layouts. IMHO what you need is either Grid Layout or Border Layout.
Related
Im trying to make a fullscreen application.
I would like to know how to make the component that I add on the JFrame to occupy a part of the screen on every resolution.
Design tab mode:
When I run on fullscreen i get this:
how can I make this following interface adjust to full screen?
Here's an idea of the some of the basic layout managers and which ones respect preferred sizes (meaning if preferred size is respected, as container expands, component will not expand with it, and vice versa)
That being said, you may want to use a BorderLayout, and place your top component at the BorderLayout.PAGE_START. Ad the screen increases, so will the component contained in that layout position. (Note: the example's main container uses a BorderLayout)
As far as the image, if you want to stretch, I'd take a look at StretchIcon from Darryl Burke. This will keep the image to a relative size.
Also a common practice is to nest panels with different layout managers, to get your desired result. You can see an example here by Andrew Thompson
Also see more about layout managers at Visual Guide to Layout Managers
I am developing a Java Swing application with Net-Beans. the application has a JFrame with tabbed panes. Now the problem is that when the frame is maximized, the tabbed pane only covers half the page and does not re-size to fit the new size of the frame.
Is there a way in Net-Beans to make the tabbed panes re-size with the enlargements of the JFrame, or does it have to be done programmatically.
If it has to be done programmatically, how would I go about it?
The sounds like a layout manager issue
Try setting the layout of the frame to BorderLayout before you add the JTabbedPane
I have problem using Grid Layout in Java Swing. I create Panel and add GridLayout with 4 columns and 2 rows.
I try to add JButton inside it, but the JButton stretch the width.
Look this image :
I want create JButton position like this, because I want to make image gallery using Java Swing.
Look this image :
Any idea? Thanks before :)
Use GridBagLayout and specify GridBagConstraints. It will help you to render components as you want
Kindly refer GridBagLayout
You can try the layout http://java-sl.com/tip_columns_flow_layout.html
It's kind of Win Explorer layout when components flow to fill columns to available width.
Is there any way to autoresize a JTabbedPane to the same size that the JFrame has?
I'm using netbeans to create the swing interface and I can't figure out whether this is a property that I can set through the GUI designer or if I have to do it programmatically. If I need to do it programatically, netbeans doesn't allow users to modify the auto generated UI code.
Thanks a lot in advance
The Visual Guide to Layout Managers should be useful for understanding how components are arranged in container.
For your task I would use BorderLayout and placed the JTabbedPane into it's center area.
For example:
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(pane, BorderLayout.CENTER);
In netbeans you just change your frame layout to BorderLayout and after that in properties for the JTabbedPane set layout constraint CENTER
I want to know if I had a component,for example,button how to able it to resize if parent component is resized by user?
This is handled by the layout manager of the container. A button at the center of a BorderLayout will resize in all directions, for example.
Read the Swing tutorial on layout managers.