Results 1 to 5 of 5

Thread: How to Resize a Component in Java?

  1. #1
    Join Date
    Aug 2006
    Posts
    287

    How to Resize a Component in Java?

    hi everyone,
    Last time you guys helped me a lot while solving the java error. So I thought instead of wasting time on searching I should directly post to you guys.!! Now I want a smaller version of a component to place on a tool palette or tool bar, which is causing me a problem. I have tried lot of things but nothing worked. Please tell me how to Resize a Component in Java? Hoping that I will get sooner response.!!
    Dimension 1100 (FMY032J) mini-tower
    2.53ghz Intel Pentium 4
    80 gig nfts HDD
    512 RAM
    Main circuit board: Dell 0CF458
    BIOS: Dell A00
    Display: Intel(R) 82865G Graphics Controller [Display adaptor]
    Multimedia: Sound MAX Integrated Digital Audio
    Windows XP Home SP2

  2. #2
    Join Date
    Jul 2006
    Posts
    286

    Re: How to Resize a Component in Java?

    Many times there is a condition where you want to create a smaller version of a component so that it can fit on a tool palette or tool bar. By setting a client property on the component, you can resize a component. The following three sizes are supported along with the regular :
    1. Mini
    2. Small
    3. Large

    Resizable components are most often used when creating charts, diagrams and similar.
    IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....

  3. #3
    Join Date
    Nov 2008
    Posts
    996

    Re: How to Resize a Component in Java?

    You should keep in mind that the one component that does not support the size variants property is JLabel. But for doing that, you have another option. You will have to change the size of a label by changing the size of its font. Before the component is displayed, you can set the size of a component with one line of code. The following code would help you to understand this :
    Code:
    myButton.putClientProperty("JComponent.sizeVariant", "mini");
    In the above code, you will have to change the size according to your need.

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to Resize a Component in Java?

    Many times it happens that even after setting the size variants property correctly, the components are displayed in its original size. When you are facing such things, then you will have to force an update to the UI. For doing this, you will have to invoke the SwingUtilities.updateComponentTreeUI(Component) method before the window is displayed. The following sample of a code may help you in that case :
    Code:
    JFrame frame = ...;
    
    SwingUtilities.updateComponentTreeUI(frame);
    
    frame.pack();
    frame.setVisible(true);

  5. #5
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to Resize a Component in Java?

    You need a panel in which absolute positioning should be enabled. The following coding may help you for the re-sizable component :
    Code:
    package resizablecomponent;
    
    import java.awt.Color;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.Dimension;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    
    public class ResizableComponentTrial extends JFrame {
    
      private JPanel panel = new JPanel(null);
      private Resizable resizer;
    
    
      public ResizableComponentTrial() {
    
          add(panel);
    
          JPanel area = new JPanel(); 
          area.setBackground(Color.gray);
          resizer = new Resizable(area);
          resizer.setBounds(70, 80, 180, 160);
          panel.add(resizer);
    
     
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setSize(new Dimension(370, 280));
          setTitle("Resizable Component");
          setLocationRelativeTo(null);
    
          addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
    
              requestFocus();
              resizer.repaint();
            }
          });
      }
    
      public static void main(String[] args) {
          ResizableComponent rc = new ResizableComponent();
          rc.setVisible(true);
      }
    }

Similar Threads

  1. How to disable component in Java Swing
    By Shaina Na in forum Software Development
    Replies: 2
    Last Post: 20-01-2012, 12:02 PM
  2. is there any possible way to resize SWF and AC3
    By Garlanka in forum Windows Software
    Replies: 9
    Last Post: 17-01-2012, 08:36 AM
  3. How to write a Component Listener in Java?
    By hariharan_00 in forum Software Development
    Replies: 4
    Last Post: 12-02-2010, 06:28 AM
  4. How to Use the ButtonGroup Component in Java?
    By hatred in forum Software Development
    Replies: 4
    Last Post: 10-02-2010, 06:36 AM
  5. How to create a JList component in java?
    By KALANI84 in forum Software Development
    Replies: 4
    Last Post: 28-01-2010, 04:11 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,914,694.54724 seconds with 17 queries