Is there a function to find a component layout position? [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
If I have a component inside a panel with a border layout (it could be any other layout), is there a way to get the component's placement in the panel layout?
For example, I add a label to a panel that has a border layout
panel.add (label, BorderLayout.NORTH);
In this case, what I want to get is the orientation of the Label inside the layout (which would be "North")

As can be seen from the API docs, specifically for BorderLayout there is getConstraints​. However, more generally neither LayoutManger nor LayoutManager2 has such a method.
Typically for these sorts of scenarios your code would keep track of the information in a convenient way. Likewise for events, it is much better to keep track than use the likes of EventObject.getSource.

Related

how to create jframe with re sizable components [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm creating a java application.there I want to keep jframe in maximized state.and I want to use it many of monitors that have different screen size.and I want to components in jframe to resize with jframe.also I need to add image to the background of the frame.that image also should resize with the jframe. how to do that?
Layout managers, layout managers, layout managers
Start by taking a look at
A Visual Guide to Layout Managers
How to Use Various Layout Managers
Using Layout Managers
You might also want to have a look at Full-Screen Exclusive Mode API, depending on what you're hoping to achieve
also I need to add image to the background of the frame.that image also should resize with the jframe. how to do that?
Java: maintaining aspect ratio of JPanel background image
How to set a background picture in JPanel
How do I resize images inside an application when the application window is resized?
I see lots of searching and research in your future.

Java Swing selecting a panel [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
If I have a grid of 9 panels within another panel and I want to be able to click a subpanel and on click, send the content of that panel to a 'selected panel' area, how would I go about this? (Imagine a character select page for a videogame. When a player selects their character, it shows an expanded view of the character in a 'selected' pane)
I'm thinking of mouseListeners for each subpanel and retrieving the clicked component but I don't understand how I can copy that clicked component to a 'selected' area.
Add your items to a JList or single-colum JTable. Add a ListSelectionListener to your chosen component. Specify ListSelectionModel.SINGLE_SELECTION. In your valueChanged() handler, the ListSelectionEvent will tell you what value was selected. Use that information to fill in the fields of an adjacent panel. A complete example, illustrated below, is seen here.

Unable to achieve particular layout of components [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have been trying to work out how could i achieve such a layout of labels, but was unsuccessful in all of my tries.
Could you give me an idea on how to achieve such a layout of labels in java?
You can nest panels with different layout managers to achieve your desired results. This can simplify the layout in many cases.
However, in this case you might be able to use a GridBagLayout. The GridBagLayout allows you to specify the row/column of each component. Start with a two column grid.
The first and second labels will take two columns on two separate rows.
Then the next four labels will each take up one column on two separate rows.
Read the section from the Swing tutorial on How to Use GridBagLayout for more information.

There have any idea for this [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have one task from my lecture which is Java. Lecturer ask us to draw a custom chess game which is something similar with the below picture. I was thinking from past few days but are not able to get at all.
Instruction :
Sorry, if I am asking question wrongly. I am expecting some ideas and any references for in able to do this.
we can write a code for you , but instead step to start will help you more to learn.
There can be many ways to write this one of is this.
Steps to start
Create a JFrame.
Set layout to border layout
Create a JPanel -> set panel at the center of jframe
Set panel layout to grid layout of 11 x 11
Create jable objects in for loop and add in Jpanel components.
Control background color of jlabel to form a structure shown in image.
For pawn, knight,you can use jlabel images
Build you logic to move or change jlabel to acive your requirement
Update and correction are invited

How to set Background Image for JInternalFrame? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I try more script to set background in JInternalFrame but no one successfull. Can anybody help me?
Basically, this is the same concept as setting the background image for a JFrame
You Could
Create JLabel, set the image as the labels icon and set the label as the JInternalFrame's content pane, making sure you set the layout manager for the label (or content pane after you changed it)
You Could
Create a custom panel, that paints the image via the panels paintComponent method
This is good if you want to make the background resizable as the window is resized
Take a look at Java: maintaining aspect ratio of JPanel background image an example
You would then, simply set this as the frame's content pane

Categories

Resources