1
Rectangle2D bounds =g.getFontMetrics().getStringBounds(message,g);

i got this error how can i solve it !

Type mismatch: cannot convert from java.awt.geom.Rectangle2D to javafx.geometry.Rectangle2D
Stultuske
  • 9,296
  • 1
  • 25
  • 37
Sa_IS
  • 33
  • 4
  • they are not in the same hierarchical tree. those types are not related, meaning you can't directly cast them. You might be able to map them, though – Stultuske May 20 '20 at 05:28

2 Answers2

1

thank you i had just changed the package into : import java.awt.geom.Rectangle2D and finally no error founded .

Sa_IS
  • 33
  • 4
-1

I can assume that you did the wrong import Rectangle2D type

In you case it javafx.geometry.Rectangle2D, but getFontMetrics().getStringBounds(...) method returns java.awt.geom.Rectangle2D

So you have to change the package import javafx.geometry.Rectangle2D to a package import java.awt.geom.Rectangle2D

Hope this helps somehow :)

S.Daineko
  • 1,790
  • 1
  • 20
  • 29
  • 2
    You 'assume' the problem, meaning this should be a comment, not an answer. Chances are, the situation as is, is trying to connect legacy to new code. – Stultuske May 20 '20 at 05:55
  • 1
    No. I decided that you have not enough information to be sure that what you are answering to is the actual question. Since the actual question is how to turn the one type in the other, it is, in fact, ignoring the actual question. Yes, it is possible that the situation should not have occurred, but I'm pretty sure the OP can see from the packages that they are two different classes. – Stultuske May 20 '20 at 06:18
  • 3
    It seems like the information is obvious. You can find the return type of this method in the documentation. Here is a common error of incorrect import and an attempt to get a different type. – S.Daineko May 20 '20 at 06:21
  • we don't even know which classes are used. – Stultuske May 20 '20 at 06:30