我试图在JScrollpane中显示一系列按钮。阅读周围,我设法退出此代码,但没有显示任何内容。我不明白可能的错误。谢谢你的帮助按照建议我做了一些更改,我编辑了但不起作用已编辑或者我很笨,或者这是其他问题。这是我带有输出图像的完整代码publicclassMainextendsjavax.swing.JFrame{privatefinalJPanelgridPanel;publicMain(){initComponents();//EXISTINGPANELgridPanel=newJPanel();JScrollPanescrollPane=newJScrollPane(gridPa
我正在尝试学习如何制作JAVA程序,并且我正在使用Swing。我试图在窗口的左上角放置一个按钮,但它一直位于顶部中心。publicvoidcreateGUI(){JFrameframe=newJFrame("MyProject");frame.setDefaultCloseOperation(3);frame.setSize(400,350);frame.setVisible(true);JPanelpanel=newJPanel();frame.add(panel);addButtonGUI(panel,newJButton(),"test",1,1);}publicvoidaddB
对于我的CSE205(Java编程2)类(class),我们必须设计一个非常简单的GUI小程序。我对Swing非常熟悉,之前在我自己的一些项目中使用过它。我设计的程序几乎没有问题,从Eclipse运行时它在我的计算机上看起来很完美:但是当我在线提交它时,它在浏览器中运行,UI变得严重困惑,返回到默认值:我已经习惯使用GridBagLayout,因为它很简单。这就是我在这里使用的。类CreatePanel和SelectPanel(如第一张图片所示)都扩展了JPanel(根据我的教授)。我设置每个使用:this.setLayout(newGridBagLayout());以及每个组件的组成
我必须为学校做这个:这是我目前的代码:importjavax.swing.*;importjava.awt.*;publicclassAddressBookGui1extendsJFrame{publicAddressBookGui1(){GridBagLayoutgbl=newGridBagLayout();GridBagConstraintsgbc=newGridBagConstraints();setLayout(gbl);JLabellabel;JButtonbutton;JTextFieldtextField;JTextAreatextArea=newJTextArea(10
我有这段代码,我试图在其中放置一个可滚动的面板(JPanel),但我不明白。这是我的代码:publicclassSniffer_GUIextendsJFrame{Canvasc=newCanvas();ConnectorPropertiesPanelprops;publicSniffer_GUI(){super("JConnectordemo");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);getContentPane().setLayout(newGridBagLayout());init();getContentPane().add
我对java中静态方法的使用感到困惑,例如,如果main方法是静态的,那是有意义的,但是在编码时我们有对象,例如JFrameframe=newJFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//herewhynotframe.EXIT_ON_CLOSE和我们使用的时候一样GridBagConstraintsc=newGridBagConstraints();//wehaveanobjectbutstillc.anchor=GridBagConstraints.PAGE_END;谁能解释一下,有什么特殊原因吗?
到目前为止,我设法尽可能避免使用GridBagLayout(手动代码),但这次我无法避免,我正在阅读SUN的教程GridBagLayout到目前为止,进展并不顺利。我想我误解了一些东西。例如,我尝试了以下代码(类似于SUN帖子中的代码):publicclassMainFrameextendsJFrame{publicstaticvoidmain(Stringargs[]){EventQueue.invokeLater(newRunnable(){publicvoidrun(){try{MainFrameframe=newMainFrame();frame.setVisible(true
好的,到目前为止,我只有一个图形用户界面(Java)和一个程序(Python)。我想要gui中的按钮按下时将输出发送到python程序并运行它。然后我希望gui程序在右侧的文本框中显示python打印命令。所以,我的问题是,这是否可能,我将如何让它发挥作用?界面importjavax.swing.*;importjavax.swing.border.EmptyBorder;importjava.awt.*;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;publicclassdogediceext
我看到GridBagLayout将它的子元素定位为在单元格内居中对齐。如何左对齐或右对齐?更新构造代码(我知道我可以重用c)//buttonpanelJPanelbutton_panel=newJPanel();button_panel.add(ok_button);button_panel.add(cancel_button);//placingcontrolstodialogGridBagConstraintsc;GridBagLayoutlayout=newGridBagLayout();setLayout(layout);c=newGridBagConstraints();c.
我看到GridBagLayout将它的子元素定位为在单元格内居中对齐。如何左对齐或右对齐?更新构造代码(我知道我可以重用c)//buttonpanelJPanelbutton_panel=newJPanel();button_panel.add(ok_button);button_panel.add(cancel_button);//placingcontrolstodialogGridBagConstraintsc;GridBagLayoutlayout=newGridBagLayout();setLayout(layout);c=newGridBagConstraints();c.