Rob Camick

Rancher
+ Follow
since Jun 13, 2009
Merit badge: grant badges
Cows and Likes
Cows
Total received
30
In last 30 days
0
Total given
0
Likes
Total received
698
Received in last 30 days
3
Total given
32
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rob Camick



When you do the rotate the string gets drawn down 250 and to the left 250, so effectively it is painted off the panel.

Instead try:


to see the difference.

If you want the starting point to be (250, 250) then try:




Another example to get you started:

2 weeks ago
Maybe instead of custom painting on your panel you can use Icons.

Check out:

1) Text Icon
2) Rotated Icon

They might allow you to be creative and use any component that can display Icons instead of doing the custom painting.
2 weeks ago
Post a proper SSCCE when asking a question.

We can't guess the context of how the code snippets are used.
1 month ago
Still not sure I understand your question.

Maybe you can use the GraphicsDevice class and then get the DisplayMode object. You can then access the screen width/height and determine which Font size you want to use for your image.
1 month ago
Suggestion removed.

A new thread has been created merging multiple questions into a single topic: https://coderanch.com/t/754939/java/Proper-Setting-Font-Size-Text
1 month ago
Post a SSCCE demonstrating your problem.

That is create two Fonts each with a different point size and display the text on a label.

If you still don't understand the difference, then ask a specific question.

The point is to try using the method first before asking the question.
1 month ago
Post a SSCCE demonstrating your problem.
1 month ago

I want to be able to draw over this image with graphics paintComponent.



1) Never do I/O in a painting method. A painting method should be efficient and only do painting.

2) Never create a component add attempt to add it to the panel in a painting method. Every time the painting method is called you end up creating a new component and adding it to the panel.

If you want to paint on top of an image, then you:

1. get rid of the JLabel.
2. read the image in the constructor of your class
3. use the drawImage(....) method to paint the image in the paintComponent(...) method
4. then do your drawOval(...). Since the drawOval is done after the drawImage, the oval will appear on top of the image.

You also need to override the getPreferredSize() method of the PaintingCanvas class so layout managers know what size your canvas should be.

1 month ago

I thought frame.pack() meant to resize the frame



It is. It will resize the frame, so all the components added to the frame are displayed at their preferred size.

Normally you don't want the frame size to keep changes as you add remove components. In this case the logic should be:



The revalidate will invoke the layout manager to reset the size/location of all the components on the panel (and frame).
2 months ago
Not really understanding what you want. Why would you have multiple text areas?

Let's say you define each text area to have 10 lines of text. When you reach the 11th line you create a new text area and add it to the frame. Now you have 100 lines of text so you have 10 text areas.

Then you delete a line of text from the first text area so now you need to shift text from the remaining 9 text areas.

Seems overly complicated to me.
2 months ago
JTable already supports a combo box as an editor.

Read the section from the Swing tutorial on Using a Combo Box as an Editor.
2 months ago
Don't use a KeyListener. It can only respond to events when a component has focus.

Instead you can use Key Bindings. You can configure key bindings to work even when a component doesn't have focus.
2 months ago

Why do you want images in the fist place?



1) That is what is being used in the example image posted and what the OP is asking about.

2) Using an image makes the walls look more realistic, than drawing a simple rectangle.
2 months ago

That sounds an inefficient way to do it...



Not understanding your comment.

The code is using an Image to represent a wall. Not sure what a Rectangle2D has to do with an image.

My suggestion is to create one horizontal image/icon and one vertical image/icon. Then you just paint the Icon in the required location.
2 months ago
Note, in your looping code you do NOT need create a new image/icon for every label you create. That is not very efficient. You can create a single Image and a single Icon. So that logic should be executed outside the loop. The Icon can then be shared by every label.

I'm not really understanding your question.  if you want horizontal and vertical walls, then just paint horizontal and vertical walls. I'm not sure what rotation has to do with it.

Maybe you question is about create a single rotated image of the horizontal image than can then be used as a vertical wall?
2 months ago