?
Solved

iPadx

Posted on 2004-10-05
8
Medium Priority
?
412 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 37

Accepted Solution

by:
zzynx earned 200 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

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

800 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