#Fixed JPanel position regardless of LAF (Swing)

59 messages · Page 1 of 1 (latest)

knotty moss
#

I am trying to set a fixed Y-coordinate position (read top-to-bottom) regardless of what look and feel is being used. Since LAFs are not consistent in their component sizes, the width and height of the JPanel may differ, and on GridBagLayout, the central position of the JPanel mostly increases in overall dimensions.

Reducing the dimensions can have a bad effect on the components in various LAFs (which could've been a solution if that wasn't the case) as they were not originally meant to be compressed to a more narrow height.

The base references are Windows and Windows Classic LAFs, both of which are at the same Y position.

A simple picture says what needs to be accomplish for all without hard-coding a static value that will stop working properly once a different system font used by the LAF (Linux being an example) comes into play.

near robinBOT
#

This post has been reserved for your question.

Hey @knotty moss! 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.

knotty moss
#

I have also created a UITest.java class that contains the minimal required components and code needed to test the whole thing.

#

It also contains an additional LAF switcher that allows you to check the coordinates using mouse position displayed in the JFrame's title on different LAFs (the upper coords of the panel, and the lines themselves)

#

@opal vigil you told me to tag you once i created the thread

opal vigil
#

yeah I can't figure it out

#

you're doing lots of weird shit

knotty moss
knotty moss
#

I'll see what i can do still

opal vigil
#

Well, first thing is that you should not be adding components to the frame during the paintComponent method

#

only use this method for raw drawing operations on the panel

#

Second, for something like this where you want a consistent style, javafx really is better imo, since you can use css to have a consistent style on all systems

opal vigil
#

okay, well that's your opinion versus mine

#

but what you're doing isn't inherently difficult I don't think

#

I could probably figure it out for you though

#

if you want to commission me for like 45 euros, I can set up your swing layout with custom drawing if you give me a design of what it should look like

#

just gonna leave that offer there, since it seems like an interesting challenge

#

@knotty moss

knotty moss
#

second-hand embarrassment from that

opal vigil
#

lmao

knotty moss
#

Swing is Swing

#

that is its own thing

opal vigil
#

it's true

knotty moss
#

so there is some difficulty to it

#

it has something to do with insets

#

and if 5 people from freelancer services, 3 of them being top-rated and somewhat expensive, ALSO couldn't handle it

#

who knows

#

if nothing really works, i'll just hard-code the position (ew but fuck it)

#

that... might actually be a not-so-bad-solution

opal vigil
#

not that the requirements of your task are difficult

knotty moss
opal vigil
#

If you explain your task and let me build a basic app from the ground up using proper swing techniques, it is not a hard task

#

but you have assembled a very strange and unintuitive bit of code that makes it difficult

knotty moss
#

i only have 3 months of experience

#

and no prior real programming experience

opal vigil
#

no, I'm not trying to offend you

#

I'm just stating it as it is

knotty moss
#

yes, but you coding something for 45 bucks doesn't teach me things better

opal vigil
#

well, unlike most people, I actually thoroughly document my code so that anyone can understand what's going on

#

but yeah, you make your own decision

knotty moss
#

well, i did already state i can't have it for ...that

#

but Swing is Swing, and if swing is a bitch to me, and i'm not told any better, i'll just force through with manual positioning

opal vigil
#

how about 30 bux

knotty moss
#

even if you asked for free, i wouldn't

opal vigil
#

damn

#

it really do be like that

knotty moss
#

if this was for a professional setting and all that, sure, i would pay big bucks no problem

opal vigil
#

you really do have the industrious american spirit though, I must commend you on that

knotty moss
#

I fixed it by using FlowLayout and setting a vertical gap

#

i shall close this now