Rob Camick

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

Recent posts by Rob Camick

See: Custom Painting Approaches for an example that allows you to paint multiple rectangles of different colors.
6 hours ago

To do so I add a MouseListener to the JComboBox in this way.

Don't add a MouseListener to a combo box. Instead you can use an ActionListener (or ItemListener). Read the Swing tutorial on How to Use Combo Boxes for more information and example.

Custom Painting Approaches may also give you some ideas. It demonstrates how to draw rectangles of a different color.
2 days ago

Can i use jscrollpane...

Not when you use a null layout. Don't use a null layout. Don't use setBounds().

Swing was designed to be used with layout managers.

Read the Swing tutorial. There are sections on:

1. Using layout managers
2. How to Use Text Areas for a simple example of using a scroll pane
3. How to Use Scroll Panes for detailed information and more complex example.

Also don't use a Thread to update the time display. You should be using a Swing Timer. The tutorial also explains what a Timer is. You can of course use Google for that as well.
1 month ago

my problems are:
1- I cannot draw
2- The program doesn't zoom in and out.

When writing code solve one problem at a time. That is first write the code for drawing and test that code. Once that works then you work on the next step. This way you are debugging smaller segments of code.
1 month ago

but encountered significant UI issues with text font, focus, and button size.

Those should not be issues as each Swing component will automatically calculate its size based on the Font and text etc.

The only time you have an issue is when you use a null layout and try to hard code sizes.

2 months ago
1) Don't override paint(). Custom painting should be done by overriding paintComponent().
2) Invoke super.paintComponent(...) first to make sure background is cleared before you do custom painting

3 months ago


That is because your component doesn't have a preferred size so it defaults to (0, 0) so there is nothing to paint.

When doing custom painting you must override the getPreferredSize() method of your class to return your desired size so the layout manager can work properly.

Read the section from the Swing tutorial on Custom Painting for more information and complete working examples.
3 months ago
Cross posted:

Don't cross post questions. Its frustrating when people take the time to help only to find out you already have an answer.
5 months ago

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:

6 months 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.
6 months ago
Post a proper SSCCE when asking a question.

We can't guess the context of how the code snippets are used.
7 months 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.
7 months ago
Suggestion removed.

A new thread has been created merging multiple questions into a single topic:
7 months 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.
7 months ago
Post a SSCCE demonstrating your problem.
7 months ago