首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在图形用户界面中使用GridLayout居中显示文本

如何在图形用户界面中使用GridLayout居中显示文本
EN

Stack Overflow用户
提问于 2016-09-10 08:36:07
回答 1查看 489关注 0票数 -1

我需要帮助创建GUI (完全新手:-( ..)

这是用GridLayout创建的,但现在我希望左侧的文本居中显示在TextArea的中间。有没有可能不一直使用"\n“?

代码:

代码语言:javascript
复制
public class guiFrame {
    JLabel label;
    JMenuBar menubar;
    JTextArea area;

    public guiFrame() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(new Dimension(600,200));
        frame.getContentPane().setBackground(Color.BLACK);

        JPanel panel = new JPanel(new BorderLayout());
        panel.setLayout(new GridLayout(1, 2));
        frame.add(panel);

        JMenuBar menubar = new JMenuBar();
        frame.setJMenuBar(menubar);
        JMenu aenderFarb = new JMenu("Ändere Farbe");
        menubar.add(aenderFarb);
        JMenuItem blak = new JMenuItem("schwarz");
        JMenuItem whit = new JMenuItem("weiß");
        aenderFarb.add(blak);
        aenderFarb.add(whit);

        JTextArea area = new JTextArea("Hallo, Welt! Hier kann man Text reinschreiben...");
        panel.add(area);
        panel.setBackground(Color.BLACK);

        JLabel label = new JLabel("");
        label.setBackground(Color.BLACK);
        panel.add(label);
        frame.setVisible(true);
    }
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39421398

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档