简体   繁体   English

同时在jframe中显示标签,即文本等和形状

[英]Displaying both labels ie text etc and shapes in jframe at same time

Im currently having trouble Displaying both labels ie text buttons etc and shapes in jframe at same time. 我当前遇到问题同时显示两个标签,即文本按钮等和jframe中的形状。 What is happening is only the shapes display when i run it. 发生的事情只是我运行时显示的形状。
Can someone tell me how to enable both to be displayed at the same time. 有人可以告诉我如何同时显示两者。 Thanks in advance 提前致谢

Below is some of the code for the labels which is in main class the shapes code is in a separate class: 下面是一些标签的代码,在主类中,形状代码在一个单独的类中:

    JLabel label1 = new JLabel (" some text wont display\n for some reason");
    c.gridx = 0;
    c.gridy = 0;

    panel.add(label1,c);

    JButton button1 = new JButton ("4");
    c.gridx = 15;
    c.gridy = 0;
    panel.add(button1,c);

    //now to call from the shapes class to have a couple of shapes.

    GuiDog object= new GuiDog();
    frame.add(object);

    object.drawing();
}

You seem to have forgotten to add panel to the frame. 您似乎忘记了将面板添加到框架中。 The code should work fine after adding it. 添加后代码应该可以正常工作。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM