[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Increase JCheckBox size

Posted on 1999-12-03
5
Medium Priority
?
2,331 Views
Last Modified: 2012-08-14
How to increase the CheckBox size automatically as window size increases?
0
Comment
Question by:kishanu
5 Comments
 
LVL 7

Expert Comment

by:Jan Louwerens
ID: 2253902
I beleive that this would depend more on the layout manager you're using, and not specifically on the check box itself.
0
 

Accepted Solution

by:
Shamsurizam earned 200 total points
ID: 2254428
Try to use GridbagLayout. The info about this layout you find it on this website :

http://www.borland.com/jbuilder/news/zd/apr98/ 



0
 
LVL 2

Expert Comment

by:meming
ID: 2256533
Don't think it's possible in AWT. Since awt controls are the native OS GUI controls, and OS companies won't like the idea.

If you are using Swing, you can do your own drawing of any control and make it work with the layoutmanagers.

Here are some options you may have as suggested in a newsgroup posting:

1. Write your own subclass of AbstractButton to draw the
checkbox however you want,
 
2. Write a subclass modifying the UI class for JCheckBox,
and tell the UIManager to use your subclass to display the
JCheckBox.
 
3. I think you can also override the UIManager's display by
subclassing JCheckBox and writing your own paint() method.
 
0
 
LVL 2

Expert Comment

by:kgreddy
ID: 2289250
Here is an examlpe where I used Border layout
and a combo box, and a close button.

Using border layout, you can position your components
at NORTH, SOUTH, EAST,WEST and CETER
positions.

/*
            A basic implementation of the JFrame class.
*/

import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;

public class verman extends com.sun.java.swing.JFrame
{
      public verman()
      {
            // This code is automatically generated by Visual Cafe when you add
            // components to the visual environment. It instantiates and initializes
            // the components. To modify the code, only use code syntax that matches
            // what Visual Cafe can generate, or Visual Cafe may be unable to back
            // parse your Java file into its visual environment.
            //{{INIT_CONTROLS
            getContentPane().setLayout(new BorderLayout());
            setSize(405,305);
            setVisible(false);
            JComboBox1.setSelectedIndex(4);
            JComboBox1.addActionListener(new comboEventHandler());
            getContentPane().add(JComboBox1, BorderLayout.NORTH);
            JComboBox1.setBounds(108,24,157,23);
            
            JButton1.setText("close");
            JButton1.setActionCommand("close");
            JButton1.setBounds(120,240,140,30);
            JButton1.addActionListener(new buttonEventHandler());
            getContentPane().add(JButton1,BorderLayout.SOUTH);

            
            //}}

            //{{INIT_MENUS
            //}}
            
            

      }
      
            
      class comboEventHandler implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
          {
                 //Write your code here  
            }
          
      }
      
      class buttonEventHandler implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
          {
             System.exit(0);
            
            
          }
          
      }
      
      
      public verman(String sTitle)
      {
            this();
            setTitle(sTitle);
      }

      public void setVisible(boolean b)
      {
            if (b)
                  setLocation(50, 50);
            super.setVisible(b);
      }

      static public void main(String args[])
      {
            (new verman()).setVisible(true);
      }

      public void addNotify()
      {
            // Record the size of the window prior to calling parents addNotify.
            Dimension size = getSize();

            super.addNotify();

            if (frameSizeAdjusted)
                  return;
            frameSizeAdjusted = true;

            // Adjust size of frame according to the insets and menu bar
            Insets insets = getInsets();
            com.sun.java.swing.JMenuBar menuBar = getRootPane().getJMenuBar();
            int menuBarHeight = 0;
            if (menuBar != null)
                  menuBarHeight = menuBar.getPreferredSize().height;
            setSize(insets.left + insets.right + size.width, insets.top + insets.bottom + size.height + menuBarHeight);
      }

      // Used by addNotify
      boolean frameSizeAdjusted = false;

      //{{DECLARE_CONTROLS
      String [] verNames = {"option1", "option2", "option3","option4","option5" };
      com.sun.java.swing.JComboBox JComboBox1 = new com.sun.java.swing.JComboBox(verNames);
      com.sun.java.swing.JButton JButton1 = new com.sun.java.swing.JButton();
      //}}

      //{{DECLARE_MENUS
      //}}

}
0
 
LVL 2

Expert Comment

by:kgreddy
ID: 2289252
Try using Border layout you can achieve
resizing of the combobox when you increase
the window size
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month8 days, 17 hours left to enroll

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question