mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Make combo box be all one piece
This commit is contained in:
@@ -4,6 +4,7 @@ import java.awt.BorderLayout;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.LayoutManager;
|
import java.awt.LayoutManager;
|
||||||
@@ -126,6 +127,20 @@ public class FComboBox<E> extends JComboBox<E> {
|
|||||||
textAlignment = align;
|
textAlignment = align;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
g2d.setPaint(getForeground());
|
||||||
|
int shapeWidth = 10;
|
||||||
|
int shapeHeight = 10;
|
||||||
|
int x = getWidth() - shapeWidth - 8;
|
||||||
|
int y = getHeight() / 2 - 2;
|
||||||
|
int[] xPoints = {x, x + shapeWidth, x + (shapeWidth/2)};
|
||||||
|
int[] yPoints = {y, y, y + (shapeHeight/2)};
|
||||||
|
g2d.fillPolygon(xPoints, yPoints, 3);
|
||||||
|
}
|
||||||
|
|
||||||
private class FComboBoxUI extends BasicComboBoxUI {
|
private class FComboBoxUI extends BasicComboBoxUI {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -147,13 +162,12 @@ public class FComboBox<E> extends JComboBox<E> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JButton createArrowButton() {
|
protected JButton createArrowButton() {
|
||||||
JButton btn = new ComboButton();
|
return new JButton() { //return button that takes up no space
|
||||||
btn.setOpaque(false);
|
@Override
|
||||||
btn.setBorderPainted(true);
|
public int getWidth() {
|
||||||
btn.setBorder(BorderFactory.createMatteBorder(0, 1, 0, 0, getBorderColor()));
|
return 0;
|
||||||
btn.setBackground(getBackground());
|
}
|
||||||
btn.setForeground(getForeground());
|
};
|
||||||
return btn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@@ -162,24 +176,6 @@ public class FComboBox<E> extends JComboBox<E> {
|
|||||||
return new CustomCellRenderer<>();
|
return new CustomCellRenderer<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ComboButton extends JButton {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void paintComponent(Graphics g) {
|
|
||||||
super.paintComponent(g);
|
|
||||||
Graphics2D g2d = (Graphics2D)g;
|
|
||||||
g2d.setPaint(getForeground());
|
|
||||||
int shapeWidth = 10;
|
|
||||||
int shapeHeight = 10;
|
|
||||||
int x = (getWidth() / 2) - (shapeWidth / 2);
|
|
||||||
int y = (getHeight() / 2) - (shapeHeight / 3); //(shapeHeight / 2) + ((shapeHeight / 4));
|
|
||||||
int[] xPoints = {x, x+shapeWidth, x+(shapeWidth/2)};
|
|
||||||
int[] yPoints = {y, y, y+(shapeHeight/2)};
|
|
||||||
g2d.fillPolygon(xPoints, yPoints, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("hiding")
|
@SuppressWarnings("hiding")
|
||||||
private class CustomCellRenderer<E> implements ListCellRenderer<E> {
|
private class CustomCellRenderer<E> implements ListCellRenderer<E> {
|
||||||
|
|
||||||
@@ -197,7 +193,6 @@ public class FComboBox<E> extends JComboBox<E> {
|
|||||||
lblItem.setHorizontalAlignment(textAlignment.getInt());
|
lblItem.setHorizontalAlignment(textAlignment.getInt());
|
||||||
return lblItem;
|
return lblItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user