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.
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 8 years ago.
Improve this question
I'm pretty new to Java and I'm currently attempting to make a simple work scheduling program. I'm trying to implement a way to add employee's and their info into but I'm a little stuck.
What I wanted to do was have a button that opens up a new window that will let me input their name (string), total hours to work per week (int), and their availability (array, check boxes that will translate to an array). Is it possible to customize a JDialog to do this or is there a better way to go about doing this? I tried reading tutorials on JDialogs but none of it explains how to implement multiple inputs.
I currently have it to where I'm opening up a new JFrame but I've read from multiple sources that I shouldn't do that.
Thanks for any help.
I tried reading tutorials on JDialogs but none of it explains how to implement multiple inputs.
This is no different than adding multiple components such as JTextFields, JRadioButtons, JComboBoxes in a JFrame. For both you'd create a main JPanel to hold the GUI, and then give it components and or other JPanels each using its own layout manager. Then create your JDialog or JFrame (using the API to see which constructor to use), add your main JPanel to the top level window (actually to its contentPane) by calling add(myMainPanel), pack the top level window by calling pack(), and display it via setVisible(true).
The key issue for a dialog window is often when to query its contents. If it's a modal dialog, then that's easy -- you query the contents (the state of its fields) after the call to display the dialog, since that code flow will resume once the dialog is no longer visible. For a non-modal dialog, then you'd need to add a WindowListener to notify you when the dialog is no longer visible.
For more specific help, you need to ask a more specific question and show code.
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 8 years ago.
Improve this question
I am aware of the methods and coding required to set a JFrame item's position and size, but I need a bit of help knowing how to correctly size and position items. Is there a way to use another JFrame API/method to separate the window into sections to make positioning items easier? What are the maximum values for height and width? How do I set a button to an average size? If you have some experience with JFrames, please give me some info about this to help me understand how to position and size JFrame items.
You shouldn't be worrying about pixel perfect positioning of components. Swing wasn't meant to be used as such. Being a language that is meant to be run on many different platforms, the GUI library should be flexible as such. To maintain the flexibility, layout managers are introduced. You should be using these layout managers do the sizing and positioning for you.
You can see a visualization of how each work at A Visual Guide to Layout Managers. With these layout managers, you'll want to learn (at the very least)
Which ones respect preferred size and which ones don't.
how each ones are represented visually.
How to create white space, using gaps, empty borders, struts
How use use nested containers with different layout managers to get your desired result.
It may intimidating with all the different possibilities, but like learning anything new, take it one step at a time. Go through each tutorial for each layout manager.
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