AIZU-WAKAMATSU, Japan—Haruyasu Miyabe used to oversee a computer-chip production line at a Fujitsu Ltd. plant here. One day last year, the plant manager told Mr. Miyabe to prepare for a career change.

"Starting tomorrow, you are going to make lettuce," he recalls being told.

Amid troubled times in the Japanese electronics industry, Fujitsu shut one of the three chip-making lines at the plant in 2009. Now, in a sterile, dust-free clean room that once built the brains of high-tech gadgets, Mr. Miyabe and a staff of about 30 tend heads of lettuce.

"We thought about a data center or a call center, but it was difficult to get approval," says Mr. Miyabe, who takes a proprietary pride in the new product. "I kind of feel attached to the lettuce as it grows. It's cute."

Mr. Miyabe and Fujitsu aren't alone in this circuit-boards-to-plowshares transition. Struggling to compete with rivals in South Korea or China in businesses like televisions and smartphones, a range of Japanese electronics giants are converting idled factories to agriculture.