GUI Elements enable / disable

Answered

Hi, I tested my plugin with the newest Pycharm 2023.3.1 and all the disabled buttons in the plugin lost the grayed-out effect, and look like they are enabled:

But they are in fact disabled - not clickable. In 2023.2.5 it was all OK:

I'm using the standard setEnabled() method for enabling/disabling the buttons. Do I need to do something additional to get the buttons look disabled and grayed-out?

 

Thanks,

Milo

0
8 comments

What API are you using here? Could you please share a code snippet?

0

Hi Yann,

It's classic JButton:

 

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

var hcpy = new JButton();
hcpy.setOpaque(false);
hcpy.setContentAreaFilled(false);
hcpy.setBorderPainted(false);
hcpy.setEnabled(false);
0

Well, I could, but at this stage I want to avoid big changes in the code, the project is in the maintain phase. There must be a reason why this stopped working in 2023.3. Maybe the New UI? What could I do to get this working with the JButton?

 

Milo

0

What happens if you disable New UI in 2023.3? Could you please share your sources or the plugin for reproducing?

0

Hi Yann,

 

with disabled New UI  the behavior is the same. I did couple of tests, and found out, that the JButton's text is correctly disabled. Only the icon always has the ‘enabled' appearance.

You can install the plugin from here: https://plugins.jetbrains.com/plugin/19828-rohde--schwarz-instrument-connectivity

However, you'd need a measurement instrument that supports VISA interface to test this. Therefore, to reproduce it, I created a simple plugin with one ToolWindow, JPanel as content with one disabled JButton - text and icon. You can see from the picture, that the text is disabled, but the icon looks enabled:

 

 

Here's the code for InstrumentsListToolWindowFactory.java :

package com.rohdeschwarz.ic;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.ContentFactory;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

public class InstrumentsListToolWindowFactory implements ToolWindowFactory, DumbAware
{
    /**
     * Create the tool window content.
     */
    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow)
    {
        var pnl = new JPanel();
        var bt = new JButton("MyDisabledButton", AllIcons.Actions.Refresh);
        bt.setEnabled(false);
        pnl.add(bt);

        var contentFactory = ContentFactory.getInstance();
        var content = contentFactory.createContent(pnl, "", false);
        toolWindow.getContentManager().addContent(content);
        toolWindow.setIcon(AllIcons.Toolwindows.Documentation);
    }
}

 

The plugin.xml file:

<!-- Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->

<idea-plugin url="https://rsicpycharmplugin.readthedocs.io/">

    <vendor url="https://www.rohde-schwarz.com">Rohde &amp; Schwarz GmbH &amp; Co. KG</vendor>

    <!-- Unique id for this plugin. Must stay constant for the life of the plugin. -->
    <id>com.rohdeschwarz.ic</id>

    <!-- Text to display as name on Preferences/Settings | Plugin page -->
    <name>Rohde &amp; Schwarz Instrument Connectivity</name>

    <!-- Indicate this plugin can be loaded in all IntelliJ Platform-based products. -->
    <depends>com.intellij.modules.platform</depends>
    <depends>com.intellij.modules.python</depends>

    <extensions defaultExtensionNs="com.intellij">

        <toolWindow
                id="Rohde &amp; Schwarz Instruments"
                secondary="true"
                icon="AllIcons.Nodes.Alias"
                anchor="right"
                factoryClass="com.rohdeschwarz.ic.InstrumentsListToolWindowFactory"
                canCloseContents="false"
        />

    </extensions>

</idea-plugin>

 

The build.gradle:

plugins
{
    id 'java'
    id 'org.jetbrains.intellij' version '1.16.1'
    id 'maven-publish'
}

group 'com.rohdeschwarz'
version '2.2.0'

//noinspection GroovyUnusedAssignment
sourceCompatibility = JavaVersion.VERSION_17
//noinspection GroovyUnusedAssignment
targetCompatibility = JavaVersion.VERSION_17

intellij
{
    version = '2023.3.1'
    type = 'PC'
    plugins = ["PythonCore"]
}

buildSearchableOptions
{
    enabled = false
}

patchPluginXml
{
    version = project.version
    sinceBuild = "231"
    untilBuild = ""
}



Hope you can help to resolve this

 

Milo

0

Sorry for delay, investigating.

0

Please sign in to leave a comment.