fix: JPopupMenu overlapping with background

This commit is contained in:
hstyi
2025-04-10 08:59:08 +08:00
committed by hstyi
parent 2568e7fcc8
commit 4f84d6741c
2 changed files with 24 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory
import java.awt.image.BufferedImage import java.awt.image.BufferedImage
import java.io.File import java.io.File
import javax.imageio.ImageIO import javax.imageio.ImageIO
import javax.swing.JPopupMenu
import javax.swing.SwingUtilities import javax.swing.SwingUtilities
class BackgroundManager private constructor() { class BackgroundManager private constructor() {
@@ -41,6 +42,23 @@ class BackgroundManager private constructor() {
} }
fun getBackgroundImage(): BufferedImage? { fun getBackgroundImage(): BufferedImage? {
assertEventDispatchThread()
val bg = doGetBackgroundImage()
if (bg == null) {
if (JPopupMenu.getDefaultLightWeightPopupEnabled()) {
return null
} else {
JPopupMenu.setDefaultLightWeightPopupEnabled(true)
}
} else {
if (JPopupMenu.getDefaultLightWeightPopupEnabled()) {
JPopupMenu.setDefaultLightWeightPopupEnabled(false)
}
}
return bg
}
private fun doGetBackgroundImage(): BufferedImage? {
synchronized(this) { synchronized(this) {
if (bufferedImage == null || imageFilepath.isEmpty()) { if (bufferedImage == null || imageFilepath.isEmpty()) {
if (appearance.backgroundImage.isBlank()) { if (appearance.backgroundImage.isBlank()) {

View File

@@ -152,8 +152,14 @@ class SettingsOptionsPane : OptionsPane() {
backgroundImageTextField.isEditable = false backgroundImageTextField.isEditable = false
backgroundImageTextField.trailingComponent = backgroundButton backgroundImageTextField.trailingComponent = backgroundButton
backgroundImageTextField.text = FilenameUtils.getName(appearance.backgroundImage) backgroundImageTextField.text = FilenameUtils.getName(appearance.backgroundImage)
backgroundImageTextField.document.addDocumentListener(object : DocumentAdaptor() {
override fun changedUpdate(e: DocumentEvent) {
backgroundClearButton.isEnabled = backgroundImageTextField.text.isNotBlank()
}
})
backgroundClearButton.isFocusable = false backgroundClearButton.isFocusable = false
backgroundClearButton.isEnabled = backgroundImageTextField.text.isNotBlank()
backgroundClearButton.icon = Icons.delete backgroundClearButton.icon = Icons.delete
backgroundClearButton.buttonType = FlatButton.ButtonType.toolBarButton backgroundClearButton.buttonType = FlatButton.ButtonType.toolBarButton