#What's the difference?

18 messages · Page 1 of 1 (latest)

bold zodiac
#
JButton = new JButton("Some Button");
JButton.setBounds(10,10,10,10);
JButton.setSize(10,10,10,10);
```What's the difference between `.setBounds` and `.setSize`? I've looked at the docs, and it doesn't make any sense so I 'm guessing I need somebody to dumb it down for me because no matter what I do with either of these methods, nothing happens with the button on the screen. Like it literally does __not__ change size or placement within the panel and my panel is setup like
```java
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(4,1));
```for 4 rows down and 1 column wide
crude hawkBOT
#

⌛ This post has been reserved for your question.

Hey @bold zodiac! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

bold zodiac
#

this is what I mean. clockIn is set with set bounds, and clockOut is set with set size, but all the buttons (even the two with neither function on them) are all the same size. I'm not quite understanding. Am I doing something wrong with the layout of the panel?

#

also, I'd like a bit of help with some conditional rendering for a welcome screen too if possible. Something like a constructor method to check the OS and display a different label based off which os is detected

public class Main
{
  public checkOS() {
    if (os.system == "darwin") {
      // display darwin os welcome label
    } else if )os.system == "linux") {
      // display linux os welcome label
    } else {
      // display windows os welcome label
    }
  }
  public static void main(string[] args) {
    // rest of code
  }
}
crude hawkBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

magic remnant
# bold zodiac ```java JButton = new JButton("Some Button"); JButton.setBounds(10,10,10,10); JB...

There is no method setSize that accepts four Integer arguments. There are:
setSize which accepts two integers, the new height and the new width of the component
setLocation which also accepts two integers, the new x and y position of the component
setBounds which accepts four integers, the new x and y position of the component as well as the new width and height of the component.
However, since you are using a Layout Manager these methods don't change the appearance of the component. The Layout Manager handles location as well as the size of the components. The three methods mentioned above are only useful if there is no Layout Manager present (which should really never be the case as the final solution).
Since you are using GridLayout all components are sized to fit their cell. The cells are generated by dividing the available space in the component by the constraints you put into place. In your case your GridLayout has just one column and four rows, meaning that each components is stretched to fit the width of the screen.
That being said, GridLayout is a pretty basic layout with not much customizability. Some more sophisticated Layout Managers are GridBagLayout, GroupLayout and SpringLayout although GroupLayout and SpringLayout are better to be used with a GUI builder since they are specifically developed for that.
About your second question:
You can get the current operating system with a system's property: System.getProperty("os.name"). You will get the full OS name for example Windows 10 therefore you might want to check if the returned String only contains a specific identifier for example win.

crude hawkBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

bold zodiac
# magic remnant There is no method `setSize` that accepts four Integer arguments. There are: `se...

Ok cool. So to make sure I understand, if I want to use a layout manager and have more customizability, then use GridBagLayout, GroupLayout, or SpringLayout otherwise, just use the panel without a layout manager, correct? The reason I use the panels is because I kind of treat it like ReactJS where everything happens within the same frame and I hide/show different panels based on what the user is selecting instead of making a bunch of different screens in a sense.

#

another small part I'm having an issue with is being able to create a border color around my JPanel, and creating visible space between the JFrame and the JPanel. I can't figure that one out either

magic remnant
#

You should never use a panel without a layout manager. Components are not resized nor moved when the window size is changed. In some rare cases where you can easily provide the functionality of a layout Manager for a small component (for example displaying a Label correctly) you might use a null layout but its incredibly rare. In regards to your second statement. Yeah you would want to only work in a single frame. Nobody wants to focus and resize a new frame each time they click on a button what you are doing is absolutely fine and encouraged.
You can use the method setBorder to provide a border for your component. A class that might provide the functionality you are after have a look at LineBorder. If your JPanel doesnt display the border you might need to do JPanel.setOpaque(false);
beforehand.

bold zodiac
#

see, this is what I have so far. I'm trying to build my own time clock system. I've never been good with back end stuff, I've always been UI/UX, even with websites. On this screen, I'm wanting to bring the buttons much smaller than they are, and if I need to change the layout manager then I can, but I want the buttons to be smaller and centered in the screen with space between them

#

like in this screenshot, I'm building the same thing but in Python. Here I can make the button smaller, or whatever I want, with self.button.setGeometry(x,y,w,h) and it not be relative to a layout manager as PySide6 doesn't have a layout manager like that, but this is similar to what I'm trying to achieve

#

like I'm trying to figure out GridBagLayout, but yea. this is very difficult to understand as a framework

crude hawkBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

magic remnant
# bold zodiac like in this screenshot, I'm building the same thing but in Python. Here I can m...

I threw together a small example using GridBagLayout rebuilding your second picture:
Its a lot to take in at first but once you get to know the workings of it its not too bad. You can also always use a GUI builder if you find the process to be too tedious. However, you should know the basic functionality of the layout you are using, so getting to know the layout and working with it manually is helpful.

crude hawkBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.