You have already gotten great responses here but I'll add a word.
As stated above, eki-ben are most commonly purchased and eaten on longer train travel, such as the shinkansen and limited express trains. I'd avoid trying to eat on the commuter and purely local trains that have inward facing, commuter-style seating as there is little time to eat and no table or other facility for such activities. The express and deluxe trains have tables or fold-down trays much like on an airplane.
Virtually any JR station except those with purely local and commuter lines will have some facility for purchasing food for the trip. The larger stations, like Shinjuku, will have many options. If you get tired of eki-ben, there is always at least one convenience store in or near the station where sandwiches and other portable foods are sold. The offerings at Japanese convenience stores are of MUCH better quality than the American counterparts. Don't be afraid of the occasional "konbini" lunch to go. In addition, the larger stations will have other food options and restaurants for before or after the trip. You won't go hungry.
One trick I use if I will be leaving early, before the usual lunch hour, is to make sure I have a few extra minutes at a major connecting station, such as Shin-Osaka Station or Hakata Station. Before moving to the next train, I'll take a moment to stop and buy a fresh, locally sourced eki-ben. Local specialties are a big part of the bento culture.
One travel food option that is higher on the "cool factor" but less so in convenience is the "trolly dolly" who sells food on the train. These used to be seen on every long-distance train and many shorter trips such as the Narita Express but are disappearing from some routes. The biggest problem with them is that they often have limited or no English and the eki-ben offerings are labeled in Japanese only. Communication can be a problem with some and actually knowing what you are buying can be a guessing game. The kiosks and stands located all over the stations will have examples under glass or plastic as mentioned above. Just look them over and point to what looks good. In the bigger stations, some "bento" offerings will actually be artfully packaged sandwiches and such for a change from the rice-based meals.
Here is a pretty good overview with some photos of shops:
http://justbento.com/handbook/bento-...station-bentos
And more photos of eki-ben than you will ever have time to look at:
https://instagram.com/explore/tags/ekiben/