透明度和 JPanel

发布于 2024-10-28 20:40:56 字数 536 浏览 3 评论 0原文

我想在单击 JTable 上的编辑按钮时显示一个表单。显示的表单应与 JTable 重叠,并且应使 jTable 变暗(就像具有透明度的黑色背景一样)。我该怎么做?我是否必须在创建 JFrame 期间将 jPanel 添加到窗口,还是应该将面板创建为单独的文件并在单击按钮时使其可见。告诉我该怎么做?

编辑

与此类似的内容

在此处输入图像描述

编辑 2

您已使用 JOption 窗格,另一个建议是使用 JDialog。但如果我使用其中任何一个,我都无法创建子窗口。我只需要从弹出的 Jdialog 窗口中调用虚拟键盘即可。我无法访问键盘,因为 JDialog 保持焦点。如何解决这个问题?

编辑 3

当前的问题是,我正在使用虚拟键盘在使用 JDialog 显示的表单中键入值。现在我无法打开虚拟键盘并使其处于活动状态。即使我打开它,它也在 JDialog 后面,并且焦点仍然在 JDialog 上。我需要关闭 JDialog 才能使用虚拟键盘。

I want to show a form when i click on edit button on the JTable. The form that is displayed should overlap the JTable and should darken the jTable (just like a black background with transparency). How do i do this ? Do i have to add the jPanel to the window during creation of JFrame or shall i create the panel as a separate file and make it visible when the button is clicked. Tell me how to do this ?

EDIT

Something similar to this

enter image description here

EDIT 2

You have used JOption pane and the other suggestion was to use JDialog. But if i use either of those i cant create child window. I just need to call virtual keyboard from the popped up Jdialog window. I cant access the keyboard as the JDialog is holding the focus. How to solve this issue ?

EDIT 3

The current problem is, i am using virtual keyboard for typing the values in the form displayed by using JDialog. Now i cant able to open the virtual Keyboard and make it active. Even if i open it it is behind the JDialog and the focus is still with JDialog. I need to close the JDialog for using the virtual keyboard.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

趁微风不噪 2024-11-04 20:40:56

我回答得有点晚,因为我正在创建一个测试程序,但我的想法与安德鲁的想法相同(对不起安德鲁,安德鲁1+):

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DarkBackground extends JPanel {
   private static final Dimension MAIN_SIZE = new Dimension(800, 500);
   private static final Color DarkColor = new Color(0, 0, 0, 60);
   private JComponent glassPane;

   public DarkBackground() {
      JButton showDialogBtn = new JButton("Show Dialog");
      showDialogBtn.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            setGlassPaneVisible(true);
            JOptionPane.showMessageDialog(DarkBackground.this, "Foo");
            setGlassPaneVisible(false);
         }
      });
      add(showDialogBtn);
      setPreferredSize(MAIN_SIZE);

   }

   public void setGlassPane(JComponent glassPane) {
      JRootPane rootpane = SwingUtilities.getRootPane(this);
      this.glassPane = glassPane; 

      rootpane.setGlassPane(glassPane);
   }

   public void setGlassPaneVisible(boolean visible) {
      glassPane.setVisible(visible);
   }

   private static void createAndShowUI() {
      DarkBackground darkBgrd = new DarkBackground();
      JFrame frame = new JFrame("DarkBackground");
      frame.getContentPane().add(darkBgrd);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
      darkBgrd.setGlassPane(new MyGlassPane(DarkColor));
   }

   public static void main(String[] args) {
      java.awt.EventQueue.invokeLater(new Runnable() {
         public void run() {
            createAndShowUI();
         }
      });
   }
}

class MyGlassPane extends JComponent {
   private Color backgroundColor;

   public MyGlassPane(Color backgroundColor) {
      this.backgroundColor = backgroundColor;
   }

   @Override
   protected void paintComponent(Graphics g) {
      super.paintComponent(g);
      g.setColor(backgroundColor);
      g.fillRect(0, 0, getWidth(), getHeight());
   }
}

I'm a little late in answering as I was creating a test program, but my idea is the same as Andrew's (sorry Andrew, and 1+ to Andrew):

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DarkBackground extends JPanel {
   private static final Dimension MAIN_SIZE = new Dimension(800, 500);
   private static final Color DarkColor = new Color(0, 0, 0, 60);
   private JComponent glassPane;

   public DarkBackground() {
      JButton showDialogBtn = new JButton("Show Dialog");
      showDialogBtn.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            setGlassPaneVisible(true);
            JOptionPane.showMessageDialog(DarkBackground.this, "Foo");
            setGlassPaneVisible(false);
         }
      });
      add(showDialogBtn);
      setPreferredSize(MAIN_SIZE);

   }

   public void setGlassPane(JComponent glassPane) {
      JRootPane rootpane = SwingUtilities.getRootPane(this);
      this.glassPane = glassPane; 

      rootpane.setGlassPane(glassPane);
   }

   public void setGlassPaneVisible(boolean visible) {
      glassPane.setVisible(visible);
   }

   private static void createAndShowUI() {
      DarkBackground darkBgrd = new DarkBackground();
      JFrame frame = new JFrame("DarkBackground");
      frame.getContentPane().add(darkBgrd);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
      darkBgrd.setGlassPane(new MyGlassPane(DarkColor));
   }

   public static void main(String[] args) {
      java.awt.EventQueue.invokeLater(new Runnable() {
         public void run() {
            createAndShowUI();
         }
      });
   }
}

class MyGlassPane extends JComponent {
   private Color backgroundColor;

   public MyGlassPane(Color backgroundColor) {
      this.backgroundColor = backgroundColor;
   }

   @Override
   protected void paintComponent(Graphics g) {
      super.paintComponent(g);
      g.setColor(backgroundColor);
      g.fillRect(0, 0, getWidth(), getHeight());
   }
}
黄昏下泛黄的笔记 2024-11-04 20:40:56

请参阅 Java 教程中的如何使用根窗格。从屏幕截图来看,您需要弹出一个 JOptionPane (或 JDialog)作为输入,并在玻璃窗格上绘制阴影。

See How to Use Root Panes in the Java Tutorial. From the screen-shot it appears you need to pop a JOptionPane (or JDialog) for the input and draw the shading on the glass pane.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文