• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to make Resize JButton() on mouse click...

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All...

I am herewith enclosed my sample code for resize the JButton(),But This one resize the when will be extend the Button Caption letters,But i want mouse click resize the without button caption or with caption.

sample code :

package Resize;

import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;

import java.awt.Dimension;
import java.awt.ComponentOrientation;

public class ReButton{
public static boolean RIGHT_TO_LEFT = false;

public static void addComponents(Container contentPane) {
if (RIGHT_TO_LEFT) {
contentPane.setComponentOrientation(
ComponentOrientation.RIGHT_TO_LEFT);
}
contentPane.setLayout(new FlowLayout());

contentPane.add(new JButton("1"));
contentPane.add(new JButton("100"));
contentPane.add(new JButton("100 100"));
contentPane.add(new JButton("100 100 100"));
contentPane.add(new JButton("100 100 100 100"));
contentPane.add(new JButton("5"));

}


private static void createAndShowGUI() {

JFrame frame = new JFrame("FlowLayoutDemo") {
public Dimension getMinimumSize() {
Dimension prefSize = getPreferredSize();
return new Dimension(100, prefSize.height);
}
};
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set up the content pane.
addComponents(frame.getContentPane());

//Display the window.
frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {

javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}

************************

Thanks for your time.

Arjun Palanichamy.
Chennai-India.
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, not sure if I understand or not, so I apologize in advance if this is off base. But it sounds like you are trying to resize the button without changing the size of the text in the button, i.e. if the button says "OK", then when the button gets bigger or smaller on resize, the size of the text "OK" stays the same. Is that right?

I think you can simply explicity set the font on the button. In the font you use, you will have to explictly set the size of the font in the contructor.

Please note, you may need to reset the same font on the resize operations (not sure, just a potential gotcha) to ovveride any default behaviors of the button on resize.
 
Arjun Palanichamy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mr.Brian.
Yes you are right. i want resize the button without any font consider.Just drag and drag the button on mouse click.do increase the Button width and height that all..

if sample Figure for please can you click this link...

http://www.eclipse.org/vep/WebContent/docs/testcases/null-layout/null-layout.htm


Thanks for your time.
Arjun Palanichamy.
[ August 21, 2006: Message edited by: Arjun Palanichamy ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic