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.
Related
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.
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
I want to implement an editor where I need to have different shapes on the left-side panel and drag and drop different shapes on the right-side panel where i should be able to drag and adjust the shapes in the editor and save the drawingpad in a file in swing.
Can anyone help with that? how do I get a a dragable shapes and simultaneously add or remove after selecting a particular shape from my drawing pad.
First, you need a Shape container package (like my Area one)
Second, if you want to drag and drop shapes from a toolbar panel, you'll need a MouseInputListener to listen for toolbar clicks on the shapes, change the cursor, and handle the drop on mouseReleased
Good luck!
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
I want to build a table, with some items, and for each item I want to have its own radioButton. but the input is dynamic. so the size of the table is dynamic, and the "ActionCommand" for each radioButton is dynamic.
what is the best way to do this?
the only way I know is to normally just make a dynamic list of radioButtons and initialize it dynamicly with the names of the items.
thank you
Depends of what you want to do after ? You have to give more details...
If it's for printing, you can take a look about JTable (or more powerful JXTable) which can handle your data with a specific model (model which you have to define).
Just remember to set the action command to each radio button before adding to the table. You'll have to take the time to read doc about this, but with some tests it givesa very good result !
Else, yeah, just a map, with the name of the item, and the radio button.
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
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