David Schmidt

+ Follow
since Jan 02, 2011
David likes ...
Eclipse IDE Slackware Windows
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 Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David Schmidt

Woot! it works

After playing around a bit, here's what it looks like:

All that was needed was a nice little

JScrollPane spane = new JScrollPane(mainPane);
window.add(spane); //add mainPane to window

And this, to make it look better when resized:
this.setPreferredSize((new Dimension(getPreferredSize().width, (int)Math.round(getPreferredSize().height * 1.5))));
(Note, the above code was in the BuildingPane class, "this" refers to each separate pane.)

9 years ago
So if I understand correctly after reading that, should I try to create a new scrollpane, then put the mainPane in it?
Like this:

JScrollPane myScrollPane = new JScrollPane();

Then I need to add a JScrollBar and use a scrollable interface?

It's a good tutorial and I read it, but it's a bit hard to apply, and some parts are hard to understand.
I would appreciate a little more help if possible.
9 years ago
Thank you so much, Darryl Burke, that was perfect

Thanks to all the others, too.
There are still a couple of problems though.

This is what I did:

mainPane: GridLayout(NumberOfItems + extraSpace, 1 column).
BuildingPane: BoxLayout(BuildingPane, BoxLayout.X_AXIS)

details about extraSpace are found in the code. It's much neater and very well commented now, so it should be easy to understand.

Here is how it looks now:

It also works when I put in more than one, but I think I really need to use scrollbars.

and place that outer panel in a JScrollPane which is added to the frame.

That is exactly what I am trying to do. I have tried setting mainPane to a JScrollPane instead of a JPanel,
and then I set the layout to a ScrollPaneLayout() instead of a GridLayout().

But when I run the program, I just get this:

This is the first time I am using scrolling. Should I try to use a JScrollBar instead of scrollPane?
I don't want to mess up my layouts just to add a scrollbar

Here is all the code, as it was when I took the first screenshot: http://pastebin.com/yMd7L16B

9 years ago
Thank you for all these helpful suggestions. I am going to try them now
9 years ago
Flow layout was okay, but when I resize vertically, it doesn't adjust the components, unlike gridlayout. Any suggestions on how I can make the label smaller in the gridlayout? Maybe use a gridlayout in a gridlayout? Please help, I am not experienced with this, at all
9 years ago
Hi, I want to create a form using swing like this:

Upgrade(Label) + Description(Textbox) + At(Label) + City(ComboBox) + Add(Button).

I have tried gridlayout, flowlayout, and many other layouts but I don't like them.
GridLayout, for example, gives as much space to the "AT" field as it does to the description textbox, which looks horrible.

In short, on the left is how it looks, and on the right is how I want it to look. I have to use layout managers,
because it is going to be an application for mobile devices, so the screen size is unpredictable.

I have put all the code here to keep this post short: http://pastebin.com/RAZnNZYP
9 years ago
thank you.

Anyway, after some trial and error I managed to solve this by like this:

9 years ago
Moreover, when I type in graph. [CTRL + SPACE], "setDrawValues" is not even visible in the intellisense menu.
This is really confusing
9 years ago
Once I changed that, it worked... which is really confusing. I tried to replicate a problem from a larger program without posting the code.

The error I get is
The method setDrawValues(String, int, int, int, int) is undefined for the type JPanel

I think it is a very stupid mistake, but I can't find it. I'll post the necessary code here:
9 years ago
I want to call "setI" from class1. Can somone help me and show me what is wrong?

Java is treating MyPanel exactly like a JPanel, and won't let me create any new methods for it
However I need to be able to call custom (and non-static) methods from the class. Is this possible?
If not, any alternatives?
9 years ago
I need to create a program that draws a graph, but for now, all I have done is two lines: the X and Y axis.
The program is designed in a way as to automatically resize the graph when the window is resized.

Is this code in some way extremely inefficient? I get TERRIBLE flickering when I resize the window, and it
really annoys me. Is there any way around this problem, or something that will at least reduce the flickering?
This is important. Any help is greatly appreciated. I will also add that I have a very high-end PC.



I have added a screenshot that shows the window flickering.
9 years ago
I don't like this line

in VB, there was a command "with" that allowed you to do something like this:
with ballArray[i]
g.fillOval(.getBallX(),.getBallY(), .getBallHeight(), .getBallWidth());
End with

I also don't like the fact that I have to use the instance of the class, (such as redBall) to be able to call the method

and the fact that I didn't find a way to pass parameters(such as the ball array) directly to paintComponent() to avoid doing this:

Any ideas? ^^ Thanks
9 years ago
haha, and our tutor keeps telling us "You can't have a resizable array". Anyway, I don't want to use arrayList for now, just normal arrays would be enough. I managed to make it draw multiple balls like this, but I'm not too happy with it to be honest.

Ball Class

Main Class

9 years ago
I am still learning about classes and Object oriented programming. I created a "Ball" class to help me learn.
This class draws a ball to a JFrame.

To use it, I use the code:

where window is a JFrame.

This works very well, the problem is that when I create more than one ball, it draws the second ball and removes the
first ball.

This is the class:

Code for main class:

Could someone kindly show me how I can modify this class to be able to draw more than one ball simultaneously?
Thank you in advance.
9 years ago