Creating a view using overlay JPanels - java

I want to create a view in swing like in the picture. I managed to create the using three horizontal panels. My question is that I can create same view using only one horizontal panel ?

In Swing, no you cannot do it with a single JPanel.

You can write your own layout manager, like they show in Creating a Custom Layout Manager.

Related

most suitable Panel layouts

Which LayOut Manager is most suitable for my GUI?
I need to make the above GUI but I didn't know which layout I basically used the flow layout(easy) just to set up all my components first.

Java revalidate(); moves Objects that have been re-positioned, back to the original location

I'm making an application in which JLabels are created and can be re-positioned using
.setLocation(x,y)
However, whenever I invoke
.setVisible(true)
the JLabels move back to their original position. I think it has something to do with
.setVisible()'s --- revalidate() function
But I am unsure of how to override or avoid revalidate() effects.
Thanks,
You don't override or change revalidate() -- rather you use the appropriate layout manager since all revalidate does is to tell the layout managers to layout the components held by this and all nested containers. One "solution" is to use a null layout, but I strongly advise against that as this will lead to hard to debug and maintain GUI's, ones that might look good on one platform and terrible on all others. Consider nesting JPanels, each using its own layout manager, and using Borders, such as an EmptyBorder, to achieve your desired GUI layout.
If your program (not the user) is setting the location of the components then don't do this. Instead use the appropriate layout manager, or combination of nested panels with different layout managers to achieve your layout.
Read the Swing tutorial on Layout Managers for more information and working examples.
JLabels are created and can be re-positioned using setLocation(x,y)
However, if you are creating an application that allows the users to drag components around the screen then you need to use a null layout so you can control the location (and the size) of each component.
However, I would recommend you take at look at Drag Layout. This is a layout manager that implements most of the layout manager functionality, but will allow you to control the location of the component.
However, whenever I invoke setVisible(true)
Also, Swing components are visible by default so there is no need to invoke that method, except on top level containers (JFrame, JDialog etc).

How to create and interact with a custom grid like sudoku of size m*n in android

I started working on an android project which looks something like the image attached below.
I created a relative layout which should now contain two layouts. A linear which has a timer and a custom layout which should have a n*n grid layout.(say 8*10) horizontal layout.
I need to interact with grids like clicking on the grid should add an image to the grid etc. Is there a better way of implementing this rather than gridview?
Thanks
You can check GridLayout but I think GridView is better for this amount of fields.

Why the JInterFrame not resizing?

I am creating one java Application which includes the JDesktopPane and JInternalFrame.
And I am using GridLayOut to set JInternalFrame
The Issue is I can't resize the JInternalFrame as per the GridLayout size
Below is One Screen Shot of Application
I want the JInnernalFrame as the grid size.
Please do help me.
Because JInternalFrames are suppose to be added to and managed by a JDesktopPane
Take a look at How to Use Internal Frames for more details
JDesktopPane isn't suppose to have a layout manager, the GridLayout is taking control and making decision about how the JInternalFrame should be managed.
Simple answer is, don't use a layout manager with a JDesktopPane. Instead use JInternalFrame#pack to size the frames, setLocation to place it and don't forget to make it visible
I want the JInnernalFrame as the grid size
Either don't use JInternalFrames this way, or provide functionality that can mimic this when you want it. Layout managers tend to be to rigid for providing both these functionalities

Does a paint app on an android phone require an xml layout?

Do i need a layout for a view for when the user "paints" on the screen? And what type of layout should i have? Can it be virtually anything? Like a white screen? Thanks.
You need to use at least one layout which will act as your holder View.
It can be a white screen or whatever you want etc.Instead of programming creating all the views make a holder View for your paint stuff and do the painting on it.
No, XML layouts are optional. You can create it programmatically:
View view = new MyCustomPaintView(context);
setContentView(view);
But XML layouts are very usefull (and strictly recommended) when you need to place many Views on a screen.

Categories