[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cp-patches] RFC: Fix for JComboBox drop down list
From: |
David Gilbert |
Subject: |
Re: [cp-patches] RFC: Fix for JComboBox drop down list |
Date: |
Thu, 29 Sep 2005 21:24:46 +0000 |
User-agent: |
Mozilla Thunderbird 1.0.6 (X11/20050728) |
Lillian Angel wrote:
On Thu, 2005-09-29 at 16:26 +0200, Roman Kennke wrote:
Am Donnerstag, den 29.09.2005, 14:51 +0000 schrieb David Gilbert:
This patch fixes a problem with the drop down list in a JComboBox where the list
keeps getting wider and wider every time it is shown. It involves a small change to
the JPopupMenu class, which I'm not familiar with, so I'm asking for comments before
I commit this:
2005-09-29 David Gilbert <address@hidden>
* javax/swing/JPopupMenu.java
(setVisible): use current size, not preferred size, when checking for
screen edge,
* javax/swing/plaf/basic/BasicComboPopup.java
(show): include top and bottom insets in preferred size.
____
Looks fine :) There is an exception being thrown, but I believe its a
problem with JList.
Lillian
Thanks, I committed this plus a small change to MetalComboBoxButton,
here is the revised ChangeLog entry:
2005-09-29 David Gilbert <address@hidden>
* javax/swing/JPopupMenu.java
(setVisible): use current size, not preferred size, when checking for
screen edge,
* javax/swing/plaf/basic/BasicComboPopup.java
(show): include top and bottom insets in preferred size,
* javax/swing/plaf/metal/MetalComboBoxButton.java
(MetalComboBoxButton): don't pass icon to super class,
(paintComponent): call super.paintComponent() and reworked label
drawing.
Using the SwingUtilities.layoutCompoundLabel() method to compute the
label position takes care of truncating long labels and adding "..." to
indicate the truncation---it works with Sun's implementation of
SwingUtilities, but not ours (yet).
Regards,
Dave
Index: javax/swing/JPopupMenu.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JPopupMenu.java,v
retrieving revision 1.25
diff -u -r1.25 JPopupMenu.java
--- javax/swing/JPopupMenu.java 28 Sep 2005 13:59:14 -0000 1.25
+++ javax/swing/JPopupMenu.java 29 Sep 2005 20:08:28 -0000
@@ -564,8 +564,7 @@
Dimension screenSize = getToolkit().getScreenSize();
boolean fit = true;
- Dimension size = this.getPreferredSize();
-
+ Dimension size = this.getSize();
if ((size.width > (rootContainer.getWidth() - popupLocation.x))
|| (size.height > (rootContainer.getHeight() -
popupLocation.y)))
fit = false;
Index: javax/swing/plaf/basic/BasicComboPopup.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicComboPopup.java,v
retrieving revision 1.7
diff -u -r1.7 BasicComboPopup.java
--- javax/swing/plaf/basic/BasicComboPopup.java 2 Jul 2005 20:32:50 -0000
1.7
+++ javax/swing/plaf/basic/BasicComboPopup.java 29 Sep 2005 20:08:30 -0000
@@ -40,6 +40,7 @@
import java.awt.Component;
import java.awt.Dimension;
+import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ItemEvent;
@@ -179,7 +180,10 @@
int popupHeight = getPopupHeightForRowCount(comboBox.getMaximumRowCount());
list.setPreferredSize(new Dimension(cbBounds.width, popupHeight));
- super.setPopupSize(cbBounds.width, popupHeight);
+ Insets insets1 = getInsets();
+ Insets insets2 = scroller.getInsets();
+ super.setPopupSize(cbBounds.width, popupHeight + insets1.top
+ + insets1.bottom + insets2.top + insets2.bottom);
// Highlight selected item in the combo box's drop down list
if (comboBox.getSelectedIndex() != -1)
Index: javax/swing/plaf/metal/MetalComboBoxButton.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalComboBoxButton.java,v
retrieving revision 1.2
diff -u -r1.2 MetalComboBoxButton.java
--- javax/swing/plaf/metal/MetalComboBoxButton.java 23 Sep 2005 16:24:27
-0000 1.2
+++ javax/swing/plaf/metal/MetalComboBoxButton.java 29 Sep 2005 20:08:30
-0000
@@ -48,6 +48,7 @@
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JList;
+import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
/**
@@ -99,7 +100,7 @@
public MetalComboBoxButton(JComboBox cb, Icon i, boolean onlyIcon,
CellRendererPane pane, JList list)
{
- super(i);
+ super();
comboBox = cb;
comboIcon = i;
iconOnly = onlyIcon;
@@ -200,6 +201,7 @@
*/
public void paintComponent(Graphics g)
{
+ super.paintComponent(g);
if (iconOnly)
{
Rectangle bounds = getBounds();
@@ -231,9 +233,14 @@
else
g.setColor(MetalLookAndFeel.getControlDisabled());
FontMetrics fm = g.getFontMetrics(comboBox.getFont());
- // FIXME: the label may need truncating with '...' and the
- // alignment needs work
- g.drawString(text, insets.left + 5, fm.getAscent() + 4);
+ Rectangle textR = new Rectangle();
+ text = SwingUtilities.layoutCompoundLabel(fm, text, null,
+ SwingConstants.TOP, SwingConstants.LEFT,
+ SwingConstants.CENTER, SwingConstants.RIGHT,
+ innerArea, new Rectangle(), textR, 0);
+ int yAdj = (textR.height - fm.getAscent()) / 2 + 1;
+ g.setFont(comboBox.getFont());
+ g.drawString(text, textR.x, textR.y + textR.height - yAdj);
}
}
}
- [cp-patches] RFC: Fix for JComboBox drop down list, David Gilbert, 2005/09/29
- Re: [cp-patches] RFC: Fix for JComboBox drop down list, Roman Kennke, 2005/09/29
- Re: [cp-patches] RFC: Fix for JComboBox drop down list, Lillian Angel, 2005/09/29
- Re: [cp-patches] RFC: Fix for JComboBox drop down list,
David Gilbert <=
- Re: [cp-patches] RFC: Fix for JComboBox drop down list, Lillian Angel, 2005/09/30
- Re: [cp-patches] RFC: Fix for JComboBox drop down list, David Gilbert, 2005/09/30
- Re: [cp-patches] RFC: Fix for JComboBox drop down list, Lillian Angel, 2005/09/30
- Re: [cp-patches] RFC: Fix for JComboBox drop down list, Roman Kennke, 2005/09/30
- Re: [cp-patches] RFC: Fix for JComboBox drop down list, David Gilbert, 2005/09/30