PopupMenuBorder implementation

This commit is contained in:
Karl Tauber
2019-09-01 14:32:31 +02:00
parent 9c96a2b07a
commit 6cf7525624
6 changed files with 86 additions and 0 deletions

View File

@@ -32,14 +32,18 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicComboBoxUI;
import javax.swing.plaf.basic.BasicComboPopup;
import javax.swing.plaf.basic.ComboPopup;
import javax.swing.text.JTextComponent;
import com.formdev.flatlaf.util.UIScale;
@@ -174,6 +178,11 @@ public class FlatComboBoxUI
};
}
@Override
protected ComboPopup createPopup() {
return new FlatComboPopup( comboBox );
}
@Override
protected void configureEditor() {
super.configureEditor();
@@ -279,4 +288,24 @@ public class FlatComboBoxUI
g.setColor( comboBox.isEnabled() ? comboBox.getBackground() : disabledBackground );
g.fillRect( bounds.x, bounds.y, bounds.width, bounds.height );
}
//---- class FlatComboPopup -----------------------------------------------
private class FlatComboPopup
extends BasicComboPopup
{
@SuppressWarnings( "rawtypes" )
FlatComboPopup( JComboBox combo ) {
super( combo );
}
@Override
protected void configurePopup() {
super.configurePopup();
Border border = UIManager.getBorder( "PopupMenu.border" );
if( border != null )
setBorder( border );
}
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2019 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.ui;
import javax.swing.UIManager;
/**
* Border for {@link javax.swing.JPopupMenu}.
*
* @uiDefault PopupMenu.borderInsets Insets
* @uiDefault PopupMenu.borderColor Color
*
* @author Karl Tauber
*/
public class FlatPopupMenuBorder
extends FlatLineBorder
{
public FlatPopupMenuBorder() {
super( UIManager.getInsets( "PopupMenu.borderInsets" ),
UIManager.getColor( "PopupMenu.borderColor" ) );
}
}

View File

@@ -122,6 +122,11 @@ MenuItemCheckBox.icon.checkmarkColor=A7A7A7
MenuItemCheckBox.icon.disabledCheckmarkColor=606060
#---- PopupMenu ----
PopupMenu.borderColor=515151
#---- ProgressBar ----
ProgressBar.background=555555

View File

@@ -124,6 +124,12 @@ PasswordField.background=@textComponentBackground
PasswordField.margin=@textComponentMargin
#---- PopupMenu ----
PopupMenu.border=com.formdev.flatlaf.ui.FlatPopupMenuBorder
PopupMenu.borderInsets=1,1,1,1
#---- PopupMenuSeparator ----
PopupMenuSeparator.height=9

View File

@@ -122,6 +122,11 @@ MenuItemCheckBox.icon.checkmarkColor=4D89C9
MenuItemCheckBox.icon.disabledCheckmarkColor=ABABAB
#---- PopupMenu ----
PopupMenu.borderColor=cdcdcd
#---- ProgressBar ----
ProgressBar.background=c4c4c4

View File

@@ -121,6 +121,11 @@ MenuItemCheckBox.icon.checkmarkColor=4D89C9
MenuItemCheckBox.icon.disabledCheckmarkColor=ABABAB
#---- PopupMenu ----
PopupMenu.borderColor=0000ff
#---- PopupMenuSeparator ----
PopupMenuSeparator.height=30