<html><head>


<style type="text/css"><!--#xc63ee9ebb21948e p.MsoNormal
{margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;}
#xc63ee9ebb21948e a:link
{color: rgb(5, 99, 193); text-decoration: underline;}
#xc63ee9ebb21948e div.WordSection1
{page: WordSection1;}
--></style><style id="css_styles" type="text/css"><!--blockquote.cite { margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc }
blockquote.cite2 {margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc; margin-top: 3px; padding-top: 0px; }
a img { border: 0px; }
table { border-collapse: collapse; }
li[style='text-align: center;'], li[style='text-align: center; '], li[style='text-align: right;'], li[style='text-align: right; '] {  list-style-position: inside;}
body { font-family: Helvetica; font-size: 9pt; }
.quote { margin-left: 1em; margin-right: 1em; border-left: 5px #ebebeb solid; padding-left: 0.3em; }
--></style>
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><div id="xd3c8c473fce94e65b3ca247f91ae7ad2"><div><span style="font-family: Calibri, sans-serif; font-size: 14.666667px;">Sorry this went so long without a reply.</span></div><div><span style="font-family:Calibri,sans-serif;font-size:14.666667px;"><br /></span></div></div></div><div>> <span style="font-family: Calibri, sans-serif; font-size: 14.666667px;">Is there a way to ask Java would the right keyboard shortcut should be?</span></div><div></div>
<div style="clear:both"><font face="Calibri, sans-serif"><span style="font-size: 14.666667px;"><br /></span></font></div><div style="clear:both"><font face="Calibri, sans-serif"><span style="font-size: 14.666667px;">Yes. Try:</span></font></div><div style="clear:both"><font face="Calibri, sans-serif"><span style="font-size: 14.666667px;"><br /></span></font></div><div style="clear:both"><font face="Calibri, sans-serif"><span style="font-size: 14.666667px;">int modifier = Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()</span></font></div><div style="clear:both"><br /></div><div style="clear:both"><font face="Calibri, sans-serif"><span style="font-size: 14.666667px;">A sample usage is below. </span></font></div><div style="clear:both"><font face="Calibri, sans-serif"><span style="font-size: 14.666667px;"><br /></span></font></div><div style="clear:both"><div style="color: rgb(8, 8, 8); font-family: "JetBrains Mono", monospace; font-size: 9.8pt;"><pre><span style="color:#0033b3;">import </span><span style="color:#000000;">javax.swing.</span>*;<br /><span style="color:#0033b3;">import </span><span style="color:#000000;">javax.swing.border.EmptyBorder</span>;<br /><span style="color:#0033b3;">import </span><span style="color:#000000;">java.awt.</span>*;<br /><span style="color:#0033b3;">import </span><span style="color:#000000;">java.awt.event.KeyEvent</span>;<br /><br /><span style="color:#0033b3;">public class </span><span style="color:#000000;">ShortcutDemo </span><span style="color:#0033b3;">extends </span><span style="color:#000000;">JFrame </span>{<br />    <span style="color:#0033b3;">public static void </span><span style="color:#00627a;">main</span>(<span style="color:#000000;">String</span>[] args) {<br />        <span style="color:#000000;">EventQueue</span>.invokeLater(<span style="color:#0033b3;">new </span><span style="color:#000000;">Runnable</span>() {<br />            <span style="color:#9e880d;">@Override<br /></span><span style="color:#9e880d;">            </span><span style="color:#0033b3;">public void </span><span style="color:#00627a;">run</span>() {<br />                <span style="color:#000000;">ShortcutDemo d </span>= <span style="color:#0033b3;">new </span>ShortcutDemo();<br />                <span style="color:#000000;">d</span>.pack();<br />                <span style="color:#000000;">d</span>.setVisible(<span style="color:#0033b3;">true</span>);<br />            }<br />        });<br />    }<br /><br />    <span style="color:#0033b3;">public </span><span style="color:#00627a;">ShortcutDemo</span>() {<br />        <span style="color:#000000;">JMenuBar menuBar </span>= <span style="color:#0033b3;">new </span>JMenuBar();<br />        <span style="color:#000000;">JMenu editMenu </span>= <span style="color:#0033b3;">new </span>JMenu(<span style="color:#067d17;">"Edit"</span>);<br />        <span style="color:#000000;">JMenuItem copyMenuItem </span>= <span style="color:#0033b3;">new </span>JMenuItem(<span style="color:#067d17;">"Copy"</span>);<br />        <span style="color:#000000;">copyMenuItem</span>.setAccelerator(<span style="color:#000000;">KeyStroke</span>.getKeyStroke(<span style="color:#000000;">KeyEvent</span>.<span style="color:#871094;font-style:italic;">VK_C</span>, <br />                <span style="background-color: rgb(255, 255, 0);"><span style="color:#000000;">Toolkit</span>.<span style="font-style:italic;">getDefaultToolkit</span>().getMenuShortcutKeyMaskEx())</span>);<br /><br />        <span style="color:#000000;">menuBar</span>.add(<span style="color:#000000;">editMenu</span>);<br />        <span style="color:#000000;">editMenu</span>.add(<span style="color:#000000;">copyMenuItem</span>);<br />        setJMenuBar(<span style="color:#000000;">menuBar</span>);<br /><br />        <span style="color:#000000;">JLabel label </span>= <span style="color:#0033b3;">new </span>JLabel(<span style="color:#067d17;">"Placeholder Label"</span>);<br />        <span style="color:#000000;">label</span>.setBorder(<span style="color:#0033b3;">new </span>EmptyBorder(<span style="color:#1750eb;">20</span>,<span style="color:#1750eb;">20</span>,<span style="color:#1750eb;">20</span>,<span style="color:#1750eb;">20</span>));<br />        getContentPane().add(<span style="color:#000000;">label</span>);<br />    }<br />}<br /></pre></div></div>
<div>Does this answer your question?</div><div id="xc80addbc881845b0b5f2ac79f58483f8"><span style="font-family: Calibri, sans-serif; font-size: 14.666667px; margin: 0px;"><br /></span></div><div id="xc80addbc881845b0b5f2ac79f58483f8"><span style="font-family: Calibri, sans-serif; font-size: 14.666667px; margin: 0px;">Regards,</span></div><div id="xc80addbc881845b0b5f2ac79f58483f8"><span style="font-family: Calibri, sans-serif; font-size: 14.666667px; margin: 0px;"> - Jeremy</span></div><div><br /></div>
<div>
<div>------ Original Message ------</div>
<div>From <a href="mailto:mark.yagnatinsky@barclays.com">mark.yagnatinsky@barclays.com</a></div>
<div>To <a href="mailto:client-libs-dev@openjdk.org">client-libs-dev@openjdk.org</a></div>
<div>Date 2/7/24, 2:47:55 PM</div>
<div>Subject how to get find out the keyboard shortcut for the paste action?</div></div><div><br /></div>
<div id="xc63ee9ebb21948e" style="word-wrap:break-word"><blockquote cite="CH3PR12MB76198C4F8B2300D806EDCCF0F9452@CH3PR12MB7619.namprd12.prod.outlook.com" type="cite" class="cite2">

<div class="WordSection1">
<p class="MsoNormal">Some swing components such as text fields have built in support for copy and paste.<o:p xmlns:o="#unknown"></o:p></p>
<p class="MsoNormal">But if you want to add such support for a component that doesn’t, then one of the things you might want to do is support standard keyboard shortcuts.<o:p xmlns:o="#unknown"></o:p></p>
<p class="MsoNormal">Luckily, there’s a tutorial for doing this kind of thing, let’s see how they do it:<o:p xmlns:o="#unknown"></o:p></p>
<p class="MsoNormal"><a href="https://docs.oracle.com/javase/tutorial/uiswing/dnd/listpaste.html">https://docs.oracle.com/javase/tutorial/uiswing/dnd/listpaste.html</a><o:p xmlns:o="#unknown"></o:p></p>
<p class="MsoNormal">Uh oh…<o:p xmlns:o="#unknown"></o:p></p>
<p class="MsoNormal">getKeyStroke("ctrl V")<o:p xmlns:o="#unknown"></o:p></p>
<p class="MsoNormal">The tutorial simply hardcodes the relevant shortcuts.<o:p xmlns:o="#unknown"></o:p></p>
<p class="MsoNormal">I suspect that this works fine on windows, and will lead Mac users to grumble.<o:p xmlns:o="#unknown"></o:p></p>
<p class="MsoNormal">Is there a way to ask Java would the right keyboard shortcut should be?<o:p xmlns:o="#unknown"></o:p></p>
<p class="MsoNormal">I suppose one could always create a scratch text field just to look through its input map, but seems a bit hacky.<o:p xmlns:o="#unknown"></o:p></p>
</div>

<p><span lang="EN-US" style="mso-ansi-language: EN-US">This message is for 
information purposes only. It is not a recommendation, advice, offer or 
solicitation to buy or sell a product or service, nor an official confirmation 
of any transaction. It is directed at persons who are professionals and is 
intended for the recipient(s) only. It is not directed at retail customers. This 
message is subject to the terms at: 
<a href="https://www.cib.barclays/disclosures/web-and-email-disclaimer.html">https://www.cib.barclays/disclosures/web-and-email-disclaimer.html</a>. 
</span></p>
<p><span lang="EN-US" style="mso-ansi-language: EN-US">For important disclosures, 
please see: 
<a href="https://www.cib.barclays/disclosures/sales-and-trading-disclaimer.html">https://www.cib.barclays/disclosures/sales-and-trading-disclaimer.html</a> 
regarding marketing commentary from Barclays Sales and/or Trading desks, who are 
active market participants; 
<a href="https://www.cib.barclays/disclosures/barclays-global-markets-disclosures.html">https://www.cib.barclays/disclosures/barclays-global-markets-disclosures.html</a> 
regarding our standard terms for Barclays Corporate and Investment Bank where we 
trade with you in principal-to-principal wholesale markets transactions; and in 
respect to Barclays Research, including disclosures relating to specific 
issuers, see: 
<a href="http://publicresearch.barclays.com">http://publicresearch.barclays.com</a>.<br />__________________________________________________________________________________ 
<br />If you are incorporated or operating in Australia, read these important 
disclosures: 
<a href="https://www.cib.barclays/disclosures/important-disclosures-asia-pacific.html">https://www.cib.barclays/disclosures/important-disclosures-asia-pacific.html</a>.<br />__________________________________________________________________________________<br />For 
more details about how we use personal information, see our privacy notice: 
<a href="https://www.cib.barclays/disclosures/personal-information-use.html">https://www.cib.barclays/disclosures/personal-information-use.html</a>. 
<br />__________________________________________________________________________________<br /></span></p>
</blockquote></div>


</body></html>