• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

advice on drawing a square wave pulse train

 
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that, very nice. I can see me using some of that code
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW how long did it take you to write that?
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats exactly what I needed,

craig thanks again
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah , the BorderLayout is the containers defult layout, interesting
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the following code I only have one Jscrollpane appearing

 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I managed to solve it by doing this,
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic