This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes advice on drawing a square wave pulse train Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "advice on drawing a square wave pulse train" Watch "advice on drawing a square wave pulse train" New topic
Author

advice on drawing a square wave pulse train

Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

I want to draw graphicaly a square wave pulse train. This will work by users pressing on a canvas and the x coord generating a toggle point (high or low switch). Can anyone reccomend any java packages or external packages where this could be done or will I have to create my own package.


Jesus lives
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

Thanks for that, very nice. I can see me using some of that code
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

BTW how long did it take you to write that?
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

As a continuation, I would like to have a stationary pulse train that is around 200 * 30000 pixels long. Obviously I will need some sort of scrollbar in my graphics window to move beetween different points in the pulse train, but I am not sure how to go about this as it seems complex.

An idea was to only display the coords in the range offset determined by the scrollbar cursor position.

Any pointers to code that does this sort of thing?

cheers
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
how long did it take you to write that
I didn't notice
will need some sort of scrollbar in my graphics window
Setting the preferred size of the component will take care of this. The parent JScrollPane asks for this Dimension when it is ready to set its scrollbars for display of its child component/view.
display the coords in the range offset determined by the scrollbar cursor position
Java clips the graphics context so our custom graphics are drawn only on the visible area.
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

Thats exactly what I needed,

craig thanks again
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

I want to add more functionality to this, however when I want to set the content pane to have a flowlayout, it distorts things and the scroll bars disappear completely

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
FlowLayout is not a good choice for this. You can add components to the other sections of the JFrames default BorderLayout (north, west, east and south). Or you can assemble the graphic component (StandingWave) with other components and add them to the center section of the layout. Making friends with the layout managers takes some patience and practice. For more information there is Lesson: Laying Out Components Within a Container with links to some useful pages:
1 — A Visual Guide to Layout Managers
2 — Using Layout Managers
3 — How to...
I added the graphic component to the center of the BorderLayout which expands it in both directions to fill the available space. Therefore I did not have to provide any size hints beyond the width (30000) which I set in the preferredSize. These little tricks come with practice and experimentation. A Flowlayout will show the component at its preferredSize which is the default height (10, I didn't change this) and the width of 30000. Another peculiarity of FlowLayout is that it does not calculate the size of components that are not visible; it reports only the size of the visible (portion of the) components in the gui. So the JScrollPane doesn't get the correct information it needs to properly display the component.
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

Ah , the BorderLayout is the containers defult layout, interesting
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

In the following code I only have one Jscrollpane appearing

Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

I managed to solve it by doing this,
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
In the following code I only have one Jscrollpane appearing
Look at the second paragraph in the discussion section of the BorderLayout api: using no constraint defaults to the center section (BorderLayout.CENTER = "Center").
The first JScrollPane is removed from the center section and the second one is added.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: advice on drawing a square wave pulse train
 
Similar Threads
Aliens?
What is a good example of association
WA #1.....word association
Gmail Buzzz
which ettiquete rule trumps the other?