首页 \ 问答 \ 如何在Swing中创建此组件?(How can I create this component in Swing?)

如何在Swing中创建此组件?(How can I create this component in Swing?)

我正在尝试创建一个应用程序,它将使用一些基本的github信息垂直列出组件。

我原来有这个

目前的进展

我想用可点击的框架(或至少带按钮的框架)替换按钮,如下所示:

____________________________________
|_____JLabel_____|_____JLabel______|
|                                  |
|_________Fixed-length label_______|
|                                  |
|_______________Button_____________| 

我对Swing开发很新,所以我不知道任何设计习语。 请原谅杂乱的代码。 这是我尝试过的。

JPanel [] panels;

private void createStubs(PriorityQueue<Issue> issues) {

    int i = 0;
    while(!issues.isEmpty()) {
        Issue issue = issues.poll();

        // Create components
        JPanel panOuter = new JPanel(new BorderLayout());
        JPanel panTop = new JPanel(new GridBagLayout());
        JPanel panTopRight = new JPanel(new BorderLayout());
        JPanel panTopLeft = new JPanel(new BorderLayout());
        JPanel panMiddle = new JPanel(new BorderLayout());
        JPanel panBottom = new JPanel();

        panTop.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));


        panTopLeft.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        panTopRight.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        panBottom.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        panMiddle.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

        // Add components to content panel
        panOuter.add(panMiddle, BorderLayout.CENTER);
        panOuter.add(panBottom, BorderLayout.SOUTH);
        panOuter.add(panTop, BorderLayout.NORTH);


        JLabel lblTopLeft = new JLabel(issue.getTitle(), JLabel.CENTER);
        JLabel lblTopRight = new JLabel(issue.getAuthor().getLogin(), JLabel.CENTER);


        JLabel lblCenter = new JLabel(issue.getBodyShort(), JLabel.CENTER);

        JButton btnBottom = new JButton("Check out this issue");

        panMiddle.add(lblCenter);
        panBottom.add(btnBottom);

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridwidth = GridBagConstraints.REMAINDER;

        panTopLeft.add(lblTopLeft, BorderLayout.NORTH);
        panTopRight.add(lblTopRight, BorderLayout.NORTH);

        panTop.add(panTopLeft, gbc);
        panTop.add(panTopRight, gbc);   


        panOuter.add(panMiddle, BorderLayout.CENTER);
        panOuter.add(panBottom, BorderLayout.SOUTH);
        panOuter.add(panTop, BorderLayout.NORTH);

        addPanels(panOuter, i);

        ++i;
    }
}

private void addPanels(JPanel panel, int i) {
    panels[i] = panel;
    add(panels[i]);
}

所以它现在看起来像这样

好一点

我怎样才能真正使标题和作者在同一条线上? 在问题之间添加换行符并使其可滚动也是很好的。

谢谢,erip


I'm trying to create an app that will vertically list components with some basic github information.

I originally had this

Current progress

I want to replace the buttons with clickable frames (or at least frames with buttons) that look like this:

____________________________________
|_____JLabel_____|_____JLabel______|
|                                  |
|_________Fixed-length label_______|
|                                  |
|_______________Button_____________| 

I'm pretty new to Swing development, so I don't know any design idioms. Please excuse the messy code. Here's what I've tried.

JPanel [] panels;

private void createStubs(PriorityQueue<Issue> issues) {

    int i = 0;
    while(!issues.isEmpty()) {
        Issue issue = issues.poll();

        // Create components
        JPanel panOuter = new JPanel(new BorderLayout());
        JPanel panTop = new JPanel(new GridBagLayout());
        JPanel panTopRight = new JPanel(new BorderLayout());
        JPanel panTopLeft = new JPanel(new BorderLayout());
        JPanel panMiddle = new JPanel(new BorderLayout());
        JPanel panBottom = new JPanel();

        panTop.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));


        panTopLeft.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        panTopRight.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        panBottom.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        panMiddle.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

        // Add components to content panel
        panOuter.add(panMiddle, BorderLayout.CENTER);
        panOuter.add(panBottom, BorderLayout.SOUTH);
        panOuter.add(panTop, BorderLayout.NORTH);


        JLabel lblTopLeft = new JLabel(issue.getTitle(), JLabel.CENTER);
        JLabel lblTopRight = new JLabel(issue.getAuthor().getLogin(), JLabel.CENTER);


        JLabel lblCenter = new JLabel(issue.getBodyShort(), JLabel.CENTER);

        JButton btnBottom = new JButton("Check out this issue");

        panMiddle.add(lblCenter);
        panBottom.add(btnBottom);

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridwidth = GridBagConstraints.REMAINDER;

        panTopLeft.add(lblTopLeft, BorderLayout.NORTH);
        panTopRight.add(lblTopRight, BorderLayout.NORTH);

        panTop.add(panTopLeft, gbc);
        panTop.add(panTopRight, gbc);   


        panOuter.add(panMiddle, BorderLayout.CENTER);
        panOuter.add(panBottom, BorderLayout.SOUTH);
        panOuter.add(panTop, BorderLayout.NORTH);

        addPanels(panOuter, i);

        ++i;
    }
}

private void addPanels(JPanel panel, int i) {
    panels[i] = panel;
    add(panels[i]);
}

So it now looks like this

Little better

How can I actually make the title and author be on the same line? It would also be nice to add line breaks between the issues and to make it scrollable.

Thanks, erip


原文:https://stackoverflow.com/questions/33198547
更新时间:2021-09-20 09:09

最满意答案

互联网上当受骗的人那么多。都是想找捷径才上当受骗呢。所以你千万不要相信这些骗子的谎言。落入圈套以后。被骗的款子,不好追回。在以后的互联网活动都一定要谨慎。不占 小便宜。不走捷径。脚踏实地。这样你就不会上当受骗了。我都快70岁的人了。每天都浏览百度知道,也在上面回答问题。发现每天都有被骗的。都是因为爱占小便宜。或者是想走捷径才上当受骗的。

其他回答

假的啊,那是职业骗子了

再看看别人怎么说的。

相关问答

更多
  • 要在电脑上登录,若是知道网址,可以直接在浏览器上登录。而若是不知道网址,则可在百度上搜索支付宝,选择标识为官网的链接点击登录。登录方式有两种,一种是输入账号密码登录,还有一种就是手机支付宝扫描电脑上的二维码登录。
  • 代码不懂 你下一个支付宝手机版就是了
  • app端将要支付的商品列表给服务端,服务端用商品列表的信息和支付宝的key再加上时间戳还有加密等步骤(有sdk)生成签好名的支付字符串,并将字符串返回给app端,app端用这个字符串调起支付宝软件进行支付,支付完成以后app端接收支付宝软件的回调信息,显示支付完成等UI界面,同时支付宝后台会异步回调给服务端支付完成的消息,服务端接收到消息修改订单状态为支付完成(支付宝一般为了防止你没收到订单完成的消息,所以会发多次相同的回调,所以需要去重),并返回给支付宝success(如果没有返回success,支付宝就 ...
  • 这个似乎要支付宝提供接口才行。不可能在不知道协议的情况下借用支付宝的功能的,因为如果你能轻松做到这点。基于数据安全、隐私等目的,我们需要向支付宝申请成为一个合作商户机构(就像1号店之类的使用支付宝一样)并分配一个商户编号。在我们申请了之后,支付宝会告诉我们用它提供的哪个 API 怎么做到,说不定还有 demo 给我们看的。
  • ==做IT的加班都是常事,而且都没加班费。收入除了工资主要就是项目奖和年终奖,当加班费了。阿里巴巴待遇相当不错,我记得是15个月工资,具体情况看你水平,反正我们系去阿里巴巴的那人本科应届月薪上W,不过不是成都,是上海
  • 互联网上当受骗的人那么多。都是想找捷径才上当受骗呢。所以你千万不要相信这些骗子的谎言。落入圈套以后。被骗的款子,不好追回。在以后的互联网活动都一定要谨慎。不占 小便宜。不走捷径。脚踏实地。这样你就不会上当受骗了。我都快70岁的人了。每天都浏览百度知道,也在上面回答问题。发现每天都有被骗的。都是因为爱占小便宜。或者是想走捷径才上当受骗的。

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。