This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

CTRL Mask on JButton  RSS feed

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to apply CTRL Mask on JButtons (i.e. i have Copy and Paste Buttons not menues), i want to apply CTRL+C for copy and CTRL+V fro paste just like we do in menus.


SOOMRO
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sir,
u can do the ctr mask on your button like this
JButton b1 =new JButton("Copy");

b1.setMnemonic('C');
when u pressed alt +c it works
[ June 25, 2004: Message edited by: Ravi Lekhwani ]
 
Ikram Soomro
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Thank You for your reply.

I know that setMnemonic can used to apply shortcutkey but it is with ALT Key

b1.setMnemonic('C'); = ALT + C

my question was how can i apply CTRL + C on JButton.
 
R.Joe
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ikram,
First Of all i m sorry 4 not sending the right solution, Now I made a code for you which gives u a exact solution ,just have a look into it, Please give me a reply weather it solves your solution or not

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;

public class Test4 extends JFrame implements ActionListener
{
JButton but1,but2;

public Test4()
{
getContentPane().setLayout(new FlowLayout());
but1 =new JButton("Close");
but2 =new JButton("Background");

but1.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent ke)
{
if (ke.getKeyCode()==KeyEvent.VK_C && ke.isControlDown())
{
dispose();
}
else if (ke.getKeyCode()==KeyEvent.VK_B && ke.isControlDown())
{
getContentPane().setBackground(Color.cyan);
}
}


});

getContentPane().add(but1);
getContentPane().add(but2);
but1.addActionListener(this);
but2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==but1)
{
dispose();
}
else if(ae.getSource()==but2)
{
getContentPane().setBackground(Color.cyan);
}
}

public static void main(String[] args)
{
Test4 tst = new Test4();
tst.setVisible(true);
tst.setSize(300,400);

}
}
 
Ikram Soomro
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ravi
Thank you for sending me right solution;
It worked...

Ikram Soomro
(SCJP,SCWCD)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!