BRUSSELS—Six months ago, President Trump said the European Union was formed to screw America. On Monday, he lavished praise on European leaders as they gathered around a table at the White House to discuss the war in Ukraine.

How European Leaders Studied Trump and Learned to Speak His Language PREMIUM How European Leaders Studied Trump and Learned to Speak His Language

He complimented German Chancellor Friedrich Merz’s tan, told EU chief Ursula von der Leyen she was perhaps the most powerful of those at the table and described 57-year-old Finnish President Alexander Stubb as young and powerful.

The change in tone is the outcome of big, painful concessions Europe has made to Trump on trade and military spending. It is also the result of careful study, European officials say.

European members of the North Atlantic Treaty Organization more than doubled their military spending—at Trump’s insistence. The EU also swallowed a lopsided trade deal that slapped 15% tariffs on their imports to the U.S.

But European leaders say the secret sauce for getting Trump’s attention and admiration is learning to speak his language. In doing so, they have begun to gain his ear and retain his support for Ukraine.

“The default setting of the Europeans is to wait, worry and complain,” said Kurt Volker, who was U.S. special representative for Ukraine during Trump’s first term.

“This is the worst instinct possible for dealing with Trump. What you need to do is be positive, do your own homework and make your own proposals and be proactive. I think Monday was a good demonstration of everybody figuring out how to do that.”

At the White House meeting this week, notes of discord were short-lived: When the French and German leaders pressed Trump to seek a cease-fire of the kind he had recently dismissed, the conversation remained cordial.

Where trans-Atlantic relations go next is of deep concern to Europeans, who fear Trump’s current support could prove fleeting. But for now they are seeing the fruits of their homework and seeking to capitalize on the results.

French President Emmanuel Macron was able to navigate contentious topics without the meeting turning sour.

NATO officials, who are used to Trump’s impatience during long diplomatic gatherings, expressed pleasant surprise at how engrossed the president appeared to be during the military alliance’s summit in June. The full-day event took place after European members pledged to spend 5% on defense.

When Trump closed the summit, which he described as “highly productive,” he said NATO is “not a rip-off.”

Here are some of the lessons Europe has learned from studying how Trump operates, according to people involved in the encounters:

Say ‘thank you’

In the Oval Office in February, Trump and Vice President JD Vance dressed down Ukrainian President Volodymyr Zelensky for allegedly failing to express thanks for U.S. support. Trump claims credit for many achievements and wants them acknowledged by others, interlocutors say. On Monday, he said several times that he had resolved six wars. The European leaders thanked Trump about 30 times for his efforts during their public meeting. Trump thanked them at least a dozen times.

Talk to Trump

Since Trump won re-election, European leaders and their teams have striven to build and maintain contact with the White House—and particularly with Trump himself. The Europeans have worked hard to coordinate among themselves so that he hears one message from many voices. Their goal has been to surround Trump with Europe’s narrative, especially reinforcing their view that Russia is the aggressor in the war in Ukraine. Now, it isn’t just Europeans calling Trump; he calls them, too. Germany’s Merz and NATO Secretary-General Mark Rutte are regulars on Trump’s call list, say officials.

Use Trump’s vocabulary

Trump loves tariffs and hates sanctions, so European leaders now talk more about using tariffs to punish Russia. Trump in recent days has also developed a distaste for the idea of a cease-fire in Ukraine, but he wants killings to stop. Von der Leyen, the EU Commission president, said in a news conference with Zelensky on Sunday that it was important not to get drawn into semantics. “Whether we call it a cease-fire or it’s a peace deal, stop the killing,” she said. Words matter with Trump, officials say.

Speak in real estate terms

Trump’s business career centered on real estate, and it is still a reference point for him. At the White House on Monday, Zelensky showed Trump a map of Ukraine to explain the situation, while European leaders compared Russian President Vladimir Putin’s territorial claims to the U.S. surrendering states such as Florida, Trump’s base outside Washington, according to officials. “Thank you for the map, by the way,” Trump told Zelensky. “It was great.”

Get friendly

Trump mixes work with family and friends. Leaders who enter the inner circle and develop a rapport with him stand a better chance of being heard. Stubb, the Finnish president, has spent hours playing golf with Trump. Italian Prime Minister Giorgia Meloni’s firebrand social conservatism has long struck a chord with the U.S. leader and his close aides, opening doors. Vance just spent a weekend with U.K. Foreign Secretary David Lammy and his family at his countryside residence. For Europe, that quality time has been priceless, officials say.

Write to Daniel Michaels at Dan.Michaels@wsj.com and Laurence Norman at laurence.norman@wsj.com