Changing the size of a JComboBox

Greetings,
I am trying to build a mechanism to perform zooming on a JPanel with an arbitrary collection of components (including nested JPanels). I've tried a number of things with little success. The following is my most promising contraption. It can zoom labels, textfields, checkboxes, and buttons. However, for some reason, the combo box refuses to accept a changes to its size. I'm not sure why this is the case. Its font changes size appropriately.
Anyway, I'm running in JDK 1.4, and the following program lays out a palette of components. To change the size of the components, hit F1 to zoom in, and F2 to zoom out.
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.KeyEventPostProcessor;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import java.awt.geom.AffineTransform;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Demo extends JPanel
    public class Zoomer
        private double m_zoom = 1;
        private JPanel m_panel;
        public Zoomer(JPanel panel)
            m_panel = panel;
        private AffineTransform getTransform()
            return AffineTransform.getScaleInstance(m_zoom, m_zoom);
        private Font transform(Font font)
            return font.deriveFont(getTransform());
        private Dimension transform(Dimension dimension)
            Dimension retval = new Dimension();
            retval.setSize(dimension.getWidth() * m_zoom, dimension.getHeight() * m_zoom);
            return retval;
        private void performZoom(Container container)
            Component[] components = container.getComponents();
            for(int i = 0; i < components.length; i++)
                Component component = (Component)components;
component.setFont(transform(component.getFont()));
component.setSize(transform(component.getSize()));
for(int i = 0; i < components.length; i++)
Component component = components[i];
if(component instanceof Container)
performZoom((Container)component);
public double getZoom()
return m_zoom;
public void setZoom(double zoom)
if(zoom > 8.0 || zoom < 0.125) return;
m_zoom = zoom;
performZoom(m_panel);
public void zoom(double factor)
setZoom(getZoom() * factor);
public Demo()
JPanel panel = new JPanel();
panel.add(buildPanel());
panel.add(buildPanel());
final Zoomer zoomer = new Zoomer(panel);
add(panel);
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(new KeyEventPostProcessor()
public boolean postProcessKeyEvent(KeyEvent e)
if(e.getID() != KeyEvent.KEY_PRESSED) return false;
if(e.getKeyCode() == KeyEvent.VK_F1)
zoomer.zoom(1.2);
if(e.getKeyCode() == KeyEvent.VK_F2)
zoomer.zoom(1/1.2);
return false;
private JPanel buildPanel()
JPanel panel = new JPanel();
panel.add(new JLabel("label: "));
panel.add(new JTextField("Hello World"));
panel.add(new JCheckBox("checkbox"));
panel.add(new JComboBox(new String[] { "Bread", "Milk", "Butter" }));
panel.add(new JButton("Hit Me!"));
return panel;
* Create the GUI and show it. For thread safety, this method should be
* invoked from the event-dispatching thread.
private static void createAndShowGUI()
// Create and set up the window.
JFrame frame = new JFrame("Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create and set up the content pane.
Demo newContentPane = new Demo();
newContentPane.setOpaque(true); // content panes must be opaque
frame.setContentPane(newContentPane);
// Display the window.
frame.pack();
frame.setVisible(true);
public static void main(String[] args)
// Schedule a job for the event-dispatching thread:
// creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable()
public void run()
createAndShowGUI();

component.setSize(transform(component.getSize()));First of all the above line is not needed. The LayoutManager will determine the bounds (size and location) of each component in the container based on the rules of the LayoutManager. The Flow Layout is the default layout manager for a panel and it simply uses the preferred size of the component as the size of the component.
So what happens is that when you change the font of the component you are changing the preferred size of the component.
So why doesn't the combo box work? Well I took a look at the preferred size calculation of the combo box (from the BasicComboBoxUI) and it actually caches the preferred size. The combo box uses a renderer, so the value is cached for performance one would assume. The method does recalculate the size when certain properties change. Note the isDisplaySizeDirty flag used in the code below:
         else if (propertyName.equals("prototypeDisplayValue")) {
                isMinimumSizeDirty = true;
                isDisplaySizeDirty = true;
                comboBox.revalidate();
         else if (propertyName.equals("renderer")) {
                isMinimumSizeDirty = true;
                isDisplaySizeDirty = true;
                comboBox.revalidate();
            }It also handles a Font property change as well:
            else if ( propertyName.equals( "font" ) ) {
                listBox.setFont( comboBox.getFont() );
                if ( editor != null ) {
                    editor.setFont( comboBox.getFont() );
                isMinimumSizeDirty = true;
                comboBox.validate();
            }but notice that the isDisplaySizeDirty flag is missing. This would seem to be a bug (but I don't know why two flags are required).
Anyway, the following change to your code seems to work:
// component.setSize(transform(component.getSize()));
if (component instanceof JComponent)
     ((JComponent)component).updateUI();
}

Similar Messages

  • How Can I Change the Size of My Home Page So That It Fills the Screen?

    I have a PowerBook G4. Up until a couple of weeks ago when I opened Safari the home page filled the screen. Something has happened and now it fills only a portion of the screen. I can move the page around, change the size slightly by using the green button next to the minimizing button, but nothing I do will enlarge it to fill the screen. I have gone to View and Preferences, but find nothing to resolve this. Please help!

    You're welcome Maureen. Glad I could help.
    Thanks for the and Aloha from Big Island.

  • How do I change the size of a windows partition on my MacBook?

    How do I change the size of a windows partition on my MacBook?

    CampTune $19 from Paragon-Software is your best bet.
    http://www.paragon-software.com/mac/

  • What is happening when I change the size of the image in the program sequence window?

    I noticed that I can change the image size of my exported file. I imported a 720 x 480 DV file into CS5.5. I went to my program sequence window and changed the settings to show the smallest image in that window. I then clicked on the image and used the handles that appear to make that small image large enough to nearly fill the screen. When I exported my final file and played the resulting WMV, the image on my screen was nearly twice as large as it would have been if I had not previously altered the image size in the program sequence window. I had to do this alteration for each clip in my timeline, or the unaltered ones would stay at the smaller size. The quality did not seem to be significantly impaired. I learned about this on a youtube video. The person who did the video claimed that this was a simple and quick way to upgrade standard video to HD. Of course this is not true. He was only changing the size of the resulting video. Does anyone know what is really happing when you do this procedure and why it changes the size of the exported  video?

    The size (resolution) of the exported video is not affected by anything you do while editing.  It is dependant solely on the resolution set in the export settings.
    Ideally you want to edit in an sequence that matches your media\, which will be the same size or larger than the required export.  In other words, the same or smaller is OK.  Making things bigger in post is not the best option.  If you need things bigger, shoot them bigger.

  • Troubles by changing the size of a bookmark header text Repot generation Toolkit

    Hello everyone
    I'm having  troubles getting the size of  a header text formatted into a different font size, I attach the code I'm using to get the work done.
    At the end I get all I want from the report generation toolkit but the text size in the header and footer . Does Anyone have a clue?
    Well the image is too small I'm getting an error when I try to post a bigger one. The thing is that the VI's used here to change the size are append report text.vi and format text.vi. The first one is used to insert text through bookmarks in the header and footer  (it works just gereat) and the second one is intended to change the size of the inserted text (it doesn't work at all) I've already used shift registers in the for loop but I get the same results. The last VI is dispose report.vi
    thanks in advance
    Attachments:
    Maquina Etdos Verifica Reporte.vi ‏94 KB

    Hello Julio9,
     sorry for the waiting I had to clean the block diagram up and take into account some data security issues before I could post the information you asked me to. I have to tell you that I already came out with a patch for the issue nonetheless it is not the correct way to solve it and I would appretiate if you or anyone else could help me to do it right.
    Here is what I changed:
    In my code at the Initialize state (within the state machine) there is the New Report.vi I opened it to get also the new report SubVI.vi opened, afterwards I selected the NI_Word.lvclass: new report subvi.vi and opened it in its code yoou can easly see the double numeric constant value for the size of the text inserted as default. I just changed it from 12 to 8 to correct the formatting. As the outcome all the text inserted through the bookmarks have the default size (8 pts). 
    I attached the new version of my code with all the documents you will need. Please follow these steps:
    1.-Open the project named Verifica Temperaturas 2010.lvproj
    2.-Run the main vi named Maquina Etdos verifica reporte 2.vi
    3.-Check the option Laboratorio de Refrigeradores:
    4.-Click OK
    5.-Complete the information as shown:
    (For Selecciona Machote pick the word document named Document.doc attached in the .zip file. For the Selecciona Archivo de temperaturas pick the Estacion1_21-02-2012.txt file also attached in the .zip file)
    6.-Press Siguiente
    After completing the steps you'll see how the document in created. As expected the size of the text in the header is 8 pts.
    Attachments:
    Verificacion_Camaras.zip ‏359 KB

  • Changing the size of a drop down list

    Hi Everyone,
    Is there anyway to change the size of a drop down list?  For example, our customer would like to make the drop down list for the Ship-To field on the logistics tab of the sales orders longer.  Currently, they cannot see the full name when they scroll through it.  Is this possible?  Depending on what Customer Code they enter, the field size appears to change.
    Thank you in advance for your help.
    Amanda

    I am using Tahoma size 10 as well. 
    Is the drop down size somehow related to the size of the first few records?  So, if those are shorter than those at the end, perhaps it doesn't adjust for the size of the bottom records.  For example, in our customer's database here's a sampling of what they have entered and the order:
    Wal-Mart 6124
    Wal-Mart 6125
    Wal-Mart 6126
    Wal-Mart 7001
    Wal-Mart Supercenter 1111
    Wal-Mart Supercenter 2094
    Wal-Mart Supercenter 3475
    The drop down box is large enough to see the Wal-Mart 6124, etc. but not large enough to see the Wal-Mart Supercenter ones at the bottom of the list (keep in mind there are over 100 ship-to's for this Business Parnter).  Does it maybe only look at the first fifty records or something like that?
    Thanks again,
    Amanda

  • Changing the Size of A screen at runtime

    Is it possible to change the size of a screen , just before it is called, or to move it it after it has been called.
    Bascally I'm using
    CALL FUNCTION 'Z_SIM_TEST' starting new task 'PDF Spools'
    to create a new screen asynchronously, in a new session, and want the user to be aware that the older session is still there?
    Thanks.

    you can use CALL SCREEN 2009 STARTING AT x-cor y-cor ENDIGN AT x-cor y-cor to put the screen. You can change x and y coordinates.

  • Changing the size of a document in Pages?

    How can you change the size of a document in pages? I need to change a poster size document to 8.5 x 11?

    Nevermind. Found it! Sorry, new to Mac

  • Changing the Size of generated graph in excel report generation toolkit

    Hi, i am trying to build a report generation vi for my Structural health monitoring system in which i need to export 3 graphs in to an excel report. The idea is to have the report on a single page, but when i paste them along with the ceiling and pillar deviation percentages, the report just exceeds the page limit. I wanted to know whether one can change the size of the graphs in excel? One can do it in word(tried that), but i dont want to use the bookmark option as it intend to put this up as a webservice in the next step. I am using LabVIEW 2009 Thanks.
    LabVIEW 8.2,8.6,2009...still learning
    Attachments:
    Report Generation SHM.vi ‏30 KB

    Hi,
    I haven't tried this myself, but looking through the report generation toolkit the "Excel format image VI" (in the Excel specific tab of the Report Genertaion window) looks to be the one you are after. The help entry for the VI says to: "Use this VI to format any type of image in a worksheet, including front panel images, images from a file, and graphs"
    Hopefully this will help.
    -CC 
    "If anyone needs me, I'll be in the Angry Dome!"

  • Changing the size of fonts in InDesign's menus and toolbars?

    Is it possible to change the size of fonts in InDesign's menus and toolbars? I'd love for the Control Panel at the top to be a bit easier to read.

    Thanks Bob, didn't see it anywhere but figured it was worth asking. I think the size is a little biased toward people with better vision than me but I guess I'll have to live with that.
    Jon

  • I need to change the size of the view for easier reading.  Is there a way to make the page view larger without affecting the form?

    Hi Guys, good product beginning however it's not as good as many of the other Adobe product's workspaces.  I cannot change the size of the view during form design work, so it's a visual strain to work in Forms Central.  Is there a way to modify the view (not affecting the width, size or font when presented on website or on paper)?

    In Photoshop CC 2014 (Windows only) it is possible to use a setting of 200% to scale the UI. On some monitors it improves readability and on others it cuts part of the application screen. To give it a try go to:
    Edit >> Preferences >> Experimental Features
    Put a check-mark in the box and click OK
    Then close PS and re-start for the change to take effect.

  • Can you change the size of the preview images on an Apple TV without changing video resolution?

    I have a 32 inch LCD TV. My room is relatively large and I can't easily see the preview images or read the text on the TV across the room. Is it possible to change the size of preview images in the menu screens without increasing the resolution of the TV itself? I think this should be possible, but can't seem to find a way to do it.

    No that's not something you can do on the Apple TV.
    If you have any suggestions that you think might enhance the Apple TV you can send Apple your feedback here.

  • For the life of me, I can't find out what size a photo is in terms of inches or how to change the size of the photo[s] so I can print them. I think I read somewhere to click edit, then click adjust. Nothing there about sizing.

    For the life of me, I can't find out what size a photo is in terms of inches or how to change the size of the photo[s] so I can print them. I think I read somewhere to click edit, then click adjust. I don't see anything about re-sizing when I click the adjust tab: only saturation and tint levels. Thank you.

    With respect to digital images, there really is no size in inches. The size is given as number of pixels horizontally and vertically. In iPhoto '09 you click the little "i" inthe lower right side of the window and it will display information related to the selected photo, including the pixel dimensions. I do not have iPhoto '11 installed so I don't know if it is the same there.
    In some applications, such as preview, it has something additional called Dots per Inch (DPI) which you would think would allow you to convert the pixel dimensions to inches. It is not a real thing, though. The DPI is determined by how large or small you have chosen to print your photo and the capabilities of your printer. 
    There is also something called Aspect Ratio, which is usually expressed in inches x inches such as 6x9 but that doesn't mean the size on the screen or when printed is 6x9.  It is the ratio of the pixel dimensions.  When cropping your photos, you will have several standard aspect ratios to choose from plus any custom ones you create.
    In iPhoto '09, after you choose Print, in the Print Setting window are the settings for the size you want the photo printed. You want to shoose a setting with the same aspect ratio of your photo. Otherwise, iPhoto will resize and/or crop your photo to fit the size you have chosen. 

  • [SOLVED]how to change the size of default font ?

    , hellow everyone. I am newbie here and I recently installed Archlinux with Awesome WM,the default size of font is too small, in some cases,the characters even can not be clearly seen,I want to change the size of fonts so that I can read words comfortablely ,what shall I do to make the font bigger? I tried to find the solution in wiki or forum but failed, thank you in advance!
    Last edited by mabier (2010-07-23 03:41:09)

    karol wrote:A never used Awesome WM but I think you're referring to some app's font - is it your shell, browser or what? Or maybe is it some toolbar or panel (I don't know if Awesome has those)?
    the fonts in firefox browser and terminal emulator xterm are too small. I can enlarge characters in firefox browser by "ctrl +", but small fonts in xterm  can not be modified by me at the beginning, but now I create and configure ~/.Xdefaults, and this problem has been solved.  the fonts in panel of Awesome WM was also very small at the first, after configuring Awesome's theme.lua file, everything is fine now.:D
    Last edited by mabier (2010-07-22 06:31:03)

  • How to change the size of redo file

    Deal all,
    I finish installed the db,and the size of redo file is 50m by default. I found many "checkpoint not complete" events in alert.log file.
    Now i want to change it to 100M and try to avoid the event appear again ,how can i do?

    As Sb has already correct reply that size of redo logs can not be changed. We have to create new bigger/smaller size of redo logs and then 'alter system switch logfile' to inactivate older logs. Now you can drop older logs. Redo logs are something a glass of water. We can not change the size of glass, if we wish to dring more/less water, we will take that sized glass and we will get that sized water.
    Remember to consider the multiplexing/grouping when doing any maintenance like this. And there may be archive log & backup space considerations.
    Hans @ http://dbaspot.com/oracle-server/33231-changing-redo-log-file-size.html
    Regards
    Girish Sharma

Maybe you are looking for

  • Delivery schedule refer to contract - total quantity handling

    Hi Experts, could any of You pls help me with an issue regarding a delivery schedule line qty created by MRP run? I have a contract with a fixed qty, and based on this contract I have created a delivery schedule, I also maintained, that MRP run shoul

  • Data from other programs being consolidated

    Here is the picture. My corporate office is in Milan Italy and they use Hyperion Schedule to consolidate financial reports from USA, Japan, Canada, Australia and all over Europe.Each country logs into Hyperion and manually inputs loads of pages of fi

  • Endless backup after hard reset

    After i hav had a hard reset of my macbok pro my time machine (with time capsule) always start doing a full backup even though it's not necessary. It seems it doesn't remeber the previous made backups. Do anyone know a solution to this? Rather anoyin

  • CS5 Optional Automate Plug-Ins Installer - I can't get it to work?

    I want this so I can print multiple items and save canvas/paper waste. I have downloaded it and followed the instructions. However when I go on Photoshop I can't see the option Picture Package, where it should be in File-Automate? I have a mac. Any i

  • Burning CD's that won't open on my PC

    I am making CD's to send images to galleries and parts of them will not open on my old PC. Parts of them open, but the pdf files won't open. The parts that open are very clumsy, and I need to open each image individually, so the contact page is impor