Solved

iPadx

Posted on 2004-10-05
8
405 Views
Last Modified: 2010-03-31
Hi,

I quite like the iPad functionality in GridBagLayout as it means I can for example, set a JComboBox so that its minimum size will always be big enough to display all the text and not have "..."
  I'm using a different layout manager and I want this iPad functionality. I guess I can get it by specifying a fixed minimum size, but then I have to specify a fixed Dimension - with iPadx I could just do iPadx = 10;  and not have to worry about the component height, so if I'm never fixing any components height then it is just using the swing defaults which is what I want.

Badly worded question, but basically how do I have iPadx functionality using a different layout manager other than GridBagLayout??

Cheers,
Cathal.
0
Comment
Question by:cathalmchale
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12225572
>> set a JComboBox so that its minimum size will always be big enough to display all the text and not have "..."
I think that if you put the JComboBox in a simple FlowLayout you'll automatically have this behaviour.
0
 

Author Comment

by:cathalmchale
ID: 12225861
>> I think that if you put the JComboBox in a simple FlowLayout you'll automatically have this behaviour.

perhaps, but if i want it to be a little bit bigger again eg, 5 or 10 pixels bigger (so that it doesnt appear squashed - a little bit of breathing room!)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12225921
That's something I solve by setting my own ListCellRenderer which has

           this.setBorder(new EmptyBorder(0,5,0,5));  // top, left, bottom, right

in it's constructor.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Accepted Solution

by:
zzynx earned 50 total points
ID: 12226031
Forget the previous:

/*
 * ExtraSpaceListCellRenderer.java
 *
 */

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

public class ExtraSpaceListCellRenderer extends DefaultListCellRenderer {
   
    /** Creates a new instance of LocalizedListCellRenderer */
    public ExtraSpaceListCellRenderer() {
    }
   
    public Component getListCellRendererComponent(
                                JList list, Object value, int index,
                                boolean isSelected, boolean cellHasFocus) {
        String displayString = "";
        if (value != null)
            displayString = "  " + value.toString() + "  ";
        return super.getListCellRendererComponent(
                list, displayString, index, isSelected, cellHasFocus);
    }    
}

and

/*
 * ComboDemo.java
 *
 */

import javax.swing.*;

public class ComboDemo extends javax.swing.JPanel {

    private javax.swing.JComboBox theComboBox;
   
    /** Creates new form ComboDemo */
    public ComboDemo() {
        initComponents();
       
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        model.addElement("Element one");
        model.addElement("Element two");
        model.addElement("Element eleven");
        model.addElement("This is a rather long one");
        theComboBox.setModel(model);
       
        theComboBox.setRenderer( new ExtraSpaceListCellRenderer() );
    }
   
    private void initComponents() {
        theComboBox = new javax.swing.JComboBox();
        add(theComboBox);
    }

   
    public static void main(String args[]) {
        // Set the windows Look & Feel
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e) { }

        JFrame f = new JFrame("Demo");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add( new ComboDemo() );
        f.setSize(500,500);
        f.setLocationRelativeTo(null);
        f.show();
    }
}

Remark: This is in the assumption that with "bigger" you meant wider (and not higher)
0
 

Author Comment

by:cathalmchale
ID: 12226032
i added this code but it doesnt seem to have had any effect ??

opCombo.setRenderer(new DefaultListCellRenderer());
((DefaultListCellRenderer)opCombo.getRenderer()).setBorder(new EmptyBorder(0,20,0,20));
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12226134
I've re-read your question:
>>I guess I can get it by specifying a fixed minimum size, but then I have to specify a fixed Dimension -
>>with iPadx I could just do iPadx = 10;  and not have to worry about the component height,
>>so if I'm never fixing any components height then it is just using the swing defaults which is what I want.

Try this in the above code:

    public ComboDemo() {
        initComponents();
       
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        model.addElement("Element one");
        model.addElement("Element two");
        model.addElement("Element eleven");
        model.addElement("This is a rather long one");
        theComboBox.setModel(model);

        Dimension d = theComboBox.getPreferredSize();
        d.setSize( 250, d.getHeight() );
        theComboBox.setMinimumSize(d);
        theComboBox.setPreferredSize(d);
    }
0
 

Author Comment

by:cathalmchale
ID: 12226515
thankyou,
they both work - i quite like the renderer solution, i just modified the constructor a little.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12226558
Thanks :)
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

726 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