JXMultiSplitPane是否在滑块调整期间导致重画?

如何解决JXMultiSplitPane是否在滑块调整期间导致重画?

| 在调整“ 0”中的分离器时,我似乎越来越频繁地要求重新粉刷。 (请参阅下面的程序) 为什么? 我有
setContinuousLayout(false)
。 只是要澄清一下:我知道在重新调整拆分窗格的尺寸后应该重新绘制。但是在分流器调整过程中,没有调整大小。拆分器在屏幕上移动。
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jdesktop.swingx.JXMultiSplitPane;
import org.jdesktop.swingx.MultiSplitLayout;

public class MultiVerticalPane<T extends Component> extends JPanel
{
    final private List<T> components;
    public MultiVerticalPane(List<? extends T> components,List<Double> weights)
    {
        this.components = new ArrayList<T>(components);
        final int n = this.components.size();
        if (weights != null && weights.size() != n)
            throw new IllegalArgumentException(
                    \"weights and components should have same length\");

        JXMultiSplitPane msp = new JXMultiSplitPane();
        msp.setContinuousLayout(false);
        msp.getMultiSplitLayout().setModel(createSplitModel(weights));
        int i = 0;
        for (T component : components)
        {
            msp.add(component,nodeTitle(i++));
        }

        setLayout(new BorderLayout());
        add(msp,BorderLayout.CENTER);
    }
    private MultiSplitLayout.Split createSplitModel(
            List<Double> weights) 
    {
        LinkedList<MultiSplitLayout.Node> nodes = 
            new LinkedList<MultiSplitLayout.Node>();
        int i = 0;
        double wtot = 0;
        for (double w : weights)
        {
            wtot += w;
        }
        for (double w : weights)
        {           
            if (i > 0)
                nodes.addFirst(new MultiSplitLayout.Divider());
            MultiSplitLayout.Leaf leaf = 
                new MultiSplitLayout.Leaf(nodeTitle(i++));
            leaf.setWeight(w/wtot);
            nodes.addFirst(leaf);
        }
        MultiSplitLayout.Split split = 
            new MultiSplitLayout.Split();
        split.setRowLayout(false);
        split.setChildren(nodes);
        return split;
    }
    private String nodeTitle(int i) {
        return String.format(\"%02d\",i);
    }

    /************ test methods *************/

    private interface Painter
    {
        public void paint(Graphics g,Rectangle bounds);
    }

    static private class RelativeGraphics
    {
        final private Graphics g;
        final private double xofs;
        final private double yofs;
        final private double xscale;
        final private double yscale;
        private double cx;
        private double cy;

        public RelativeGraphics(Graphics g,Rectangle bounds)
        {
            this.g = g;
            this.cx = 0;
            this.cy = 0;
            this.xofs = bounds.getMinX();
            this.yofs = bounds.getMaxY();
            this.xscale = bounds.getWidth();
            this.yscale = -bounds.getHeight();
        }
        public void moveTo(double x,double y)
        {
            this.cx = x;
            this.cy = y;
        }
        public void lineTo(double x,double y)
        {
            this.g.drawLine(
                (int)(this.cx*this.xscale+this.xofs),(int)(this.cy*this.yscale+this.yofs),(int)(x*this.xscale+this.xofs),(int)(y*this.yscale+this.yofs)
            );
            moveTo(x,y);
        }           
        public void rmoveTo(double dx,double dy)
        {
            moveTo(this.cx+dx,this.cy+dy);
        }           
        public void rlineTo(double dx,double dy)
        {
            lineTo(this.cx+dx,this.cy+dy);
        }           
    }

    // adapted from http://en.wikipedia.org/wiki/Hilbert_curve#Java
    static private class HilbertCurve
    {
        final private RelativeGraphics rg;
        final private double d;
        public HilbertCurve(RelativeGraphics rg,int level)
        {
            this.rg = rg;
            double d0 = 1.0;
            for (int i = level; i > 0; i--)
                d0 /= 2;
            this.d = d0;
            rg.rmoveTo(d0/2,d0/2);
            drawCurveUp(level);
        }
        private void drawCurveUp(int n) 
        {           
            if (n > 0) {
                drawCurveLeft(n-1);    this.rg.rlineTo(0,this.d);
                drawCurveUp(n-1);      this.rg.rlineTo(this.d,0);
                drawCurveUp(n-1);      this.rg.rlineTo(0,-this.d);
                drawCurveRight(n-1);
            }
        }

        private void drawCurveLeft(int n)
        {
            if (n > 0) {
                drawCurveUp(n-1);      this.rg.rlineTo(this.d,0);
                drawCurveLeft(n-1);    this.rg.rlineTo(0,this.d);
                drawCurveLeft(n-1);    this.rg.rlineTo(-this.d,0);
                drawCurveDown(n-1);
            }
        }

        private void drawCurveRight(int n)
        {
            if (n > 0) {
                drawCurveDown(n-1);     this.rg.rlineTo(-this.d,0);
                drawCurveRight(n-1);    this.rg.rlineTo(0,-this.d);
                drawCurveRight(n-1);    this.rg.rlineTo(this.d,0);
                drawCurveUp(n-1);
            }
        }

        private void drawCurveDown(int n)
        {
            if (n > 0) {
                drawCurveRight(n-1);    this.rg.rlineTo(0,-this.d);
                drawCurveDown(n-1);     this.rg.rlineTo(-this.d,0);
                drawCurveDown(n-1);     this.rg.rlineTo(0,this.d);
                drawCurveLeft(n-1);
            }
        }
    }

    static private class HilbertPainter implements Painter
    {
        final private int level;
        public HilbertPainter(int level) { this.level = level; }
        @Override public void paint(Graphics g,Rectangle bounds) {
            new HilbertCurve(
                new RelativeGraphics(g,new Rectangle(new Point(0,0),bounds.getSize())),this.level);
        }
    }

    static private class PainterPanel extends JPanel
    {
        final private Painter painter;

        public PainterPanel(Painter painter)
        {
            this.painter = painter;
            setBackground(Color.WHITE);
            setForeground(Color.RED);
        }
        @Override public void paintComponent(Graphics g) 
        {
            super.paintComponent(g);
            this.painter.paint(g,getBounds());
        }
    }

    public static void main(String[] args) { test(); }
    private static void test() 
    {
        JFrame frame = new JFrame(\"MultiVerticalPane test\");
        List<JPanel> panels = new ArrayList<JPanel>();
        List<Double> weights = Arrays.asList(1.0,1.0,2.0,4.0,8.0);

        for (int i = 0; i < 5; ++i)
        {
            panels.add(new PainterPanel(new HilbertPainter(i+4)
                {
                    int count = 0;
                    @Override public void paint(Graphics g,Rectangle bounds)
                    {
                        super.paint(g,new Rectangle(bounds.getLocation(),new Dimension(bounds.width,bounds.height-10)));
                        g.drawString(String.format(\"%d\",this.count++),bounds.height);
                    }
                }
            ));
        }       
        MultiVerticalPane<Component> mvp = 
            new MultiVerticalPane<Component>(panels,weights);
        mvp.setPreferredSize(new Dimension(360,720));
        frame.setContentPane(mvp);
        frame.pack();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}
    

解决方法

        看来
setContinuousLayout()
影响
revalidate()
,而不是
repaint()
。     ,        它不是“直接”答案。我将其放在此处,因为我在评论中用完了空间。 我认为这不是太频繁吗?您为什么认为您将其与其他任何组件进行了比较? 我的想法是,每次调整组件大小都会检测到它称为重绘。最重要的是布局管理器如何处理调整大小。请注意,例如,当您调整最顶部面板的大小并将其向下拖动时,很少会重新粉刷,您不能说出他的邻居。当您向上拖动滑块时,情况将相反。 顺便说一句:我可能会问,您为什么要担心多长时间一次以及拆分面板的哪一部分被重新粉刷? 请记住,我不是该组件重画机制的内部专家,但是我怀疑SwingX会在这方面放弃默认设置。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-