Block entire swing ui except for one component - “dialog style”

前端 未结 4 1665
旧时难觅i
旧时难觅i 2021-01-23 20:19

[This question is in relation to this question]

Setting: I have this home-crafted \"editable label\" component which looks like a label, but when you cl

4条回答
  •  心在旅途
    2021-01-23 21:03

    In you editable label, when you start editing, use SwingUtilities.getRoot() to get the root of your label, cast it to Container. On the Container you can call getComponents(). Iterate through this array and call setEnabled(false) unless it is the label. Enable them when you're done editing.

    One question: why do you need it? If you need dialog-like behavior, use JOptionPane.

    BTW, if you remove border from JTextField and setOpaque(false), it will be just as an editable label.

提交回复
热议问题