java - Swing 组合框的相当烦人的问题
问题描述
https://youtu.be/8djixdHNoEQ - 该视频显示了我所面临的情况,因为它JComboBox
似乎多次显示/留下残像。
这是我设置组合框的方式:
private String[] list = { "Inches/Centimeters", "Miles/Kilometres", "Pounds/Kilograms", "Gallons/Litres", "Feet/Metres", "Celcius/Kelvin", "Acres/Hectare" }; //the String array the ComboBox uses
private JComboBox<String> conversionCombo; //defining the JComboBox.
conversionCombo = new JComboBox<String>(list); // creating JComboBox
除了定义它使用的列表、组合框本身和创建组合框之外,没有其他代码与该组件交互。(除了设置组合框并将其添加到屏幕等的代码之外)
下面的示例程序。
thing1(驱动类,设置 JFrame):
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class thing1 {
public static void main(String[] args) throws IOException {
JFrame frame = new JFrame("Thing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thing2 thing2 = new thing2();
frame.getContentPane().add(thing2);
frame.pack();
frame.setVisible(true);
}
}
thing2(设置 UI 元素 - 在本例中只是 JComboBox):
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JComboBox;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class thing2 extends JPanel {
/**
* Declaring all variables and components to be used within the GUI
*/
private String[] list = { "Inches/Centimeters", "Miles/Kilometres", "Pounds/Kilograms", "Gallons/Litres", "Feet/Metres", "Celcius/Kelvin", "Acres/Hectare" };
thing2() {
JComboBox<String> conversionCombo = new JComboBox<String>(list); // creating JComboBox
add(conversionCombo);
setPreferredSize(new Dimension(800, 80));
setBackground(Color.WHITE);
}
}
应该能够编译这个并看到问题。在这种情况下,如果您要从下拉列表中选择任何内容并将鼠标移动到组合框的右侧,而您的鼠标位于其中(例如:https ://i.imgur.com/Z2Slrl3.gifv ),“之后-图像”将出现。
解决方案
推荐阅读
- swift - 包含视图的动态结构数组
- angular - 不同组件中的角度路线导航
- json - 创建单个对象时,对象会两次存储到 django 数据库中。如何解决这种意外行为?
- kotlin - 使用 Kotlin 时如何修复 IDEA 中接口使用错误中的`@JvmStatic`?
- firebase - Firebase - Analytics:用户参与度图表未显示 screen_view 事件
- java - Java Mission Control 未检测到 JVM Windows 10
- sql - 如何避免在 ClickHouse 的另一个聚合函数中使用聚合函数
- vue.js - 在动态表中搜索输入
- javascript - 停止悬停时 CSS 中的过渡
- ios - 如何动态增加滚动视图中两个表格视图的高度