以编程方式从组件创建和选择值 - Swing(Programatically Create and Select Values From Components - Swing)
我有这个方法在点击时向JPanel添加了一些指令,一个按钮和JLabel,但我需要一些方法来选择这三个元素,这样我就可以设置它们的样式,我正在使用迭代所有组件并找到我想要设计风格,但它不会让我设置JPanels的边框,当你查看可用的方法时,它不是一个选项。 无论如何在底部的循环中设置JLabel的边界? 或者一种单独选择每个元素的方法。
当用户单击其他JPanel上的按钮时,将运行GenerateImageArea方法。
public void GenerateImageArea(int id) { areaHeight += 200; // Extends JPanel i++; gbc.gridx = 0; gbc.gridy = i; gbc.gridwidth = 4; gbc.anchor = GridBagConstraints.LINE_START; // Add the instructions JLabel add(new JLabel("["+ (id+5) + "]: Select an image of maximum dimensions 720 * 350 pixels."), gbc); i++; gbc.gridx = 0; gbc.gridy = i; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.LINE_START; // Add a button to load an image add(new JButton("Load Image")); gbc.gridx = 1; gbc.gridwidth = 3; // Add the JLabel which acts as a space to display the image add(new JLabel("")); // Set colour + font of the instructions JLabel for (int i = 0; i < this.getComponentCount(); i++) { Component comp = this.getComponent(i); if (comp.toString().contains("]:")) { comp.setForeground(Settings.SITE_GREEN); comp.setFont(Settings.SUBTITLEFONT); } else if (comp.toString().contains("")) { // I need to change the border of the second JLabel } } }
与此类似,我需要以编程方式添加JTextAreas然后样式,并在用户单击提交后从中检索数据。 我如何以编程方式添加组件,但之后能够提取输入?
I've got this method which adds some instructions, a button and JLabel to a JPanel on click but I need some way of selecting these three elements so I can style them, I'm using a solution of iterating through all components and finding the ones I want to style but It won't let me set the border of the JPanels, it's not an option when you view available methods. Is there anyway to set the border of the JLabel in the loop at the bottom? OR a way to individually select each element.
When the user clicks a button on a different JPanel the GenerateImageArea method runs.
public void GenerateImageArea(int id) { areaHeight += 200; // Extends JPanel i++; gbc.gridx = 0; gbc.gridy = i; gbc.gridwidth = 4; gbc.anchor = GridBagConstraints.LINE_START; // Add the instructions JLabel add(new JLabel("["+ (id+5) + "]: Select an image of maximum dimensions 720 * 350 pixels."), gbc); i++; gbc.gridx = 0; gbc.gridy = i; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.LINE_START; // Add a button to load an image add(new JButton("Load Image")); gbc.gridx = 1; gbc.gridwidth = 3; // Add the JLabel which acts as a space to display the image add(new JLabel("")); // Set colour + font of the instructions JLabel for (int i = 0; i < this.getComponentCount(); i++) { Component comp = this.getComponent(i); if (comp.toString().contains("]:")) { comp.setForeground(Settings.SITE_GREEN); comp.setFont(Settings.SUBTITLEFONT); } else if (comp.toString().contains("")) { // I need to change the border of the second JLabel } } }
Similar to this I need to programatically add JTextAreas then style and retrieve the data from them after the user clicks submit. How can i programatically add components but be able to extract the input afterwards?
原文:
最满意答案
如果你想成为jQuery从你的javascript调用异步调用,那么一个好去处就是jQuery网站
A good place to go if you are going to be jQuery to make asynch calls from your javascript is the jQuery website
相关问答
更多-
通过本地客户端程序获取服务器mysql数据库信息[2023-04-27]
ajax -
好吧,所以我为这个看似年龄的人工作只是为了找到答案很简单。 我只需要将脚本加载到_Employees局部视图中! 我想这必须在视图刷新后完成。 我已经更新了我的代码以供您观看。 Okay, so I worked on this for what seemed like ages only to find the answer was simple. I just needed to load the script into the _Employees partial view! I guess this ...
-
它使用jquery load()和允许它仅选择相关传入节点的功能来实现此目的。 这取自http://msdn.microsoft.com/en-us/magazine/hh288075.aspx 为了允许脚本仅应用于WebGrid,它使用jQuery选择器来标识具有ajaxGrid类集的元素。 该脚本使用jQuery live方法(api.jquery.com/live)为排序和分页链接(通过网格容器内的表头或页脚标识)建立单击处理程序。 这为匹配选择器的现有和未来元素设置了事件处理程序,这很方便,因为脚本 ...
-
您可能正在达到单个域的最大连接数限制,在IE8中为6。 ( 详见此处 。)我不确定IE9,但由于没有关于它的新闻稿,我认为它没有改变。 根据这篇SO帖子 ,它在Chrome中也是6。 你的6个浏览器窗口是否有任何长时间运行的请求打开,这可能会阻止第7个ajax调用? 同样的SO帖子说Firefox中的连接限制为8,所以也许您可以尝试运行该应用程序并查看问题是否仍然存在。 You might be hitting the limit on the maximum number of connections t ...
-
MVC4和Simplemembership(MVC4 and Simplemembership)[2023-01-12]
Internet模板不会添加许多不必要的文件。 它将添加处理用户登录和注册所需的控制器,视图和模型。 如果从Empty MVC项目开始,则必须从头开始创建这些项目。 如果你想从头开始,我会看看开源项目SimpleSecurity ,它将SimpleMembership与你的MVC应用程序分离。 这里有一篇文章描述了这种方法 ,它可以更容易地将SimpleMembership合并到Empty MVC项目中。 您可以查看SimpleSecurity项目中的示例,以便复制所需的控制器,视图和模型。 该示例添加了电 ... -
你完成了以下吗? 右键单击模型的设计器表面。 从上下文菜单中选择添加代码生成项目。 在打开的“添加新项”对话框中,从左侧安装的模板类型列表中选择代码。 选择ADO.NET DbContext生成器,然后单击添加按钮。 以上是Julie Lerman的指导。 http://msdn.microsoft.com/en-us/data/gg685489.aspx 如果你有,在你的控制器,确保你有 using NameofProject.Models; 并从数据库中打开表格,创建实体: NameofProjectE ...
-
我想通了,解决方案是循环并使用模型的索引。 以下是视图中解决问题的新部分 - @{ var counter = 1; for (int i = 0; i < Model.balunList.Count; i++) {