yeah there are a number of ways to do it you can do panel.setBackgroundColor(1.0f, 1.0f, 1.0f,1.0f) change the number like 0.5f = half that color its r b g i think and then capacity
A little confused with Background in UIElements.
-
- English
- angriff
- Thread is marked as Resolved.
A new update is now available, introducing seasons and more!
Latest hotfix: 0.8.0.1 (2024-12-20)
Latest hotfix: 0.8.0.1 (2024-12-20)
-
-
setBackgroundColor(0.1f, 0.1f, 0.1f, 0.75f);
you can do 0,0,0,0 or 1,1,1,1 but you need to 0.1f as 0.1 is a double 0.1f is float
-
Thanks .. I just confirmed it every time I used the floats without the f it kept giving me a lossy error. If I put the the hard integers like 255 or 160, Netbeans accept it but made it pink for some reason so it confused me to what was going on. I just came back here to let you know it confirmed to work. Now If I could just turn the dang thing off.
-
setBackgroundColor(0.1f, 0.1f, 0.1f, 0.75f);
you can do 0,0,0,0 or 1,1,1,1 but you need to 0.1f as 0.1 is a double 0.1f is float
I am starting to see double.
-
Thanks .. I just confirmed it every time I used the floats without the f it kept giving me a lossy error. If I put the the hard integers like 255 or 160, Netbeans accept it but made it pink for some reason so it confused me to what was going on. I just came back here to let you know it confirmed to work. Now If I could just turn the dang thing off.
a double and float are much the same thing but you can have bigger numbers with a double over a float, when the number is small like 1.0 or 0.75 just add f for float like 0.75f netbeans shouldn't give any errors with that for a double you can do 0.0d for an int just do 123,123,112
i don't think BackgroundColor(); supports doubles anyway ive never tried 1.0d lol only floats or integers
-
The main difference between them is precision, doubles are x2 (double) the precision of a float (floating point). A float will loose precision when working with fractions (a double will too, but not as much).
Try a repeating decimal or recurring decimal with a float (or a double) and you'll find the output is "almost" right, but not. You'll get something like 1.99999988 instead of 2.00002001 (random key bashes there to visualise).
But yes, use a float.
-
-
Thanks guys not knowing that there is a difference in the number ranges between the types was not the issue but rather, the notation to declare them with in statement notation ( ie. the f and d ), The API clearly says that the parameter argument s in public void setBackgroundColor(float r, float g, float b, float a) are floats. The problem was not even the calculation of the 0 to 1 requirement which is the desired RGB number (0 to 255) divided by 255.
The fact that any number between 0 and 1 was giving the same pink background results led to a further confusion. It was my error making the assumption that the Constructor would recognize the decimal form 0.62 (160/255) as in of itself a legitimate float. It requires the input to declare the decimal form number as f (Float), Further NETBEANS does not have the information to know the parameter argument can only be a valid float and determines that the decimal number can be either a float or double and assumes a double then flags a lossy conversion error and will not compile.
panel.setBackgroundColor(0.2f,1f,0.62f,0.8f); has no ERROR Flag
panel.setBackgroundColor(0.2,1,0.62,0.8); has an incompatible types: possible lossy conversion error from double to float. ERROR Flag
So NetBeans took the decimal numbers to be ,as default, doubles and would try to convert them to float during compile. I can only imagine at this point had NetBeans not assumed the decimals numbers are Double as default that this valuable reinforcement would not have been available on using notation and its requirement importance.
<posted this as clarification of the next person searching the forums for help on a UI panel background.>
-
not knowing that there is a difference in the number ranges between the types was not the issue
Welllllll, yes and no....
Anyways glad you have it sorted.
-
Welllllll, yes and no....
Anyways glad you have it sorted.
So you think 0.2 is NOT both an double and float possible number? but as far as sorted, yes I am too as it was annoying and significant progress has been made on my GUI.
So here is another similar issue.
exitbutton.setFontColor(50,999,999,50);
vs
titlepanel.setFontColor(0.125f,0.61f,0.11f,1.0f);
Neither gives an error in Netbeans.
The latter produces a greenish font the former a red one.
-
So you think 0.2 is NOT both an double and float possible number?
possible yes. but if you do 0.2 its a double to java just like 0 can be a long or int but you will get errors casting 0 to long. to cast 0 long its 0L.
-
possible yes. but if you do 0.2 its a double to java just like 0 can be a long or int but you will get errors casting 0 to long. to cast 0 long its 0L.
Ya well java default is double even though the only form the constructor can use is a float. Hence the lossy error. I appreciate the help as you have to realize I did this 8 years ago for the first time for about a year or two with this game then stopped and just now picking back up again. Prior to this my experience with programming was Fortran in University over 50 year ago and programmable controller logic, not as a programmer but as a Chief engineer designing heavy machinery with a team of 70. Seven or so were C++ programmers for proprietary embedded processors.
This is my fun hobby. Hope someone learns something from this discussion in java semantics because I certainly did as well as got my background colors on my GUI to be correct.
-
So you think 0.2 is NOT both an double and float possible number?
Correct.
Because 0.2f is a float and 0.2d is a double.
-
I'm not trying to be argumentative. I'm just saying they are different.
I've programming in Java since 1998.Fortran is a low level programming language (as you know), and Java is high level Object-oriented programming (OOP).
I think angriff, people are only trying to help...
-
So you think 0.2 is NOT both an double and float possible number?
Yet you need the last word in what I found confusing
You ASKED me a question. I answered.
Seriously Angriff, you need to chill.
Good luck mate.
-
red51
Moved the thread from forum Help to forum New Plugin API.
Participate now!
Don’t have an account yet? Create a new account now and be part of our community!