JList不会出现在JFrame上(JList won't show up on JFrame)
除了列表没有显示在JFrame上的事实之外,一切正常。 我不明白为什么我不能在没有声明新布局的情况下添加内容。
import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; import java.awt.event.*; public class Gui3 extends JFrame { private JPanel mousepanel; private JLabel statusbar; private JList list; private static String[] colornames = {"black","blue","red","white"}; private static Color[] colors = {Color.BLACK, Color.BLUE,Color.RED,Color.WHITE}; public Gui3(){ super("The title"); list = new JList(colornames); list.setVisibleRowCount(4); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setFixedCellHeight(15); list.setFixedCellWidth(100); add(new JScrollPane(list)); list.addListSelectionListener( new ListSelectionListener(){ public void valueChanged(ListSelectionEvent event){
用户应该能够从列表中选择背景颜色,然后程序应该将背景更改为该颜色。 但是不是......
mousepanel.setBackground(colors[list.getSelectedIndex()]); } } ); mousepanel = new JPanel(); mousepanel.setBackground(Color.WHITE); add(mousepanel, BorderLayout.CENTER); statusbar = new JLabel("Default"); add(statusbar, BorderLayout.SOUTH); HandlerClass handler = new HandlerClass(); mousepanel.addMouseListener(handler); mousepanel.addMouseMotionListener(handler); } private class HandlerClass implements MouseListener, MouseMotionListener { @Override public void mouseClicked(MouseEvent event) { statusbar.setText(String.format("Clicked at %d, %d", event.getX(),event.getY())); DrawShapes shapes = new DrawShapes(); shapes.setPosition(event.getX(), event.getY()); add(shapes); } @Override public void mousePressed(MouseEvent event){ statusbar.setText("You pressed down the mouse"); } @Override public void mouseReleased(MouseEvent event){ statusbar.setText("You released the button"); } @Override public void mouseEntered(MouseEvent event){ statusbar.setText("You entered the area"); mousepanel.setBackground(Color.RED); } @Override public void mouseExited(MouseEvent event){ statusbar.setText("The mouse has left the window"); mousepanel.setBackground(Color.WHITE); } //These are mouse motion events @Override public void mouseDragged(MouseEvent event){ statusbar.setText("You are dragging the mouse"); } @Override public void mouseMoved(MouseEvent event){ statusbar.setText("You are moving the mouse"); } } }
Everything works except for the fact that the list doesn't show up on the JFrame. I don't understand why I can't add things without declaring a new layout.
import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; import java.awt.event.*; public class Gui3 extends JFrame { private JPanel mousepanel; private JLabel statusbar; private JList list; private static String[] colornames = {"black","blue","red","white"}; private static Color[] colors = {Color.BLACK, Color.BLUE,Color.RED,Color.WHITE}; public Gui3(){ super("The title"); list = new JList(colornames); list.setVisibleRowCount(4); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setFixedCellHeight(15); list.setFixedCellWidth(100); add(new JScrollPane(list)); list.addListSelectionListener( new ListSelectionListener(){ public void valueChanged(ListSelectionEvent event){
The user should be able to select the background color from the list and then the program should change the background to that color. But is isn't...
mousepanel.setBackground(colors[list.getSelectedIndex()]); } } ); mousepanel = new JPanel(); mousepanel.setBackground(Color.WHITE); add(mousepanel, BorderLayout.CENTER); statusbar = new JLabel("Default"); add(statusbar, BorderLayout.SOUTH); HandlerClass handler = new HandlerClass(); mousepanel.addMouseListener(handler); mousepanel.addMouseMotionListener(handler); } private class HandlerClass implements MouseListener, MouseMotionListener { @Override public void mouseClicked(MouseEvent event) { statusbar.setText(String.format("Clicked at %d, %d", event.getX(),event.getY())); DrawShapes shapes = new DrawShapes(); shapes.setPosition(event.getX(), event.getY()); add(shapes); } @Override public void mousePressed(MouseEvent event){ statusbar.setText("You pressed down the mouse"); } @Override public void mouseReleased(MouseEvent event){ statusbar.setText("You released the button"); } @Override public void mouseEntered(MouseEvent event){ statusbar.setText("You entered the area"); mousepanel.setBackground(Color.RED); } @Override public void mouseExited(MouseEvent event){ statusbar.setText("The mouse has left the window"); mousepanel.setBackground(Color.WHITE); } //These are mouse motion events @Override public void mouseDragged(MouseEvent event){ statusbar.setText("You are dragging the mouse"); } @Override public void mouseMoved(MouseEvent event){ statusbar.setText("You are moving the mouse"); } } }
原文:https://stackoverflow.com/questions/36001768
最满意答案
解决方法
在一些常见的.js文件中定义
function showMyIndicator() { busyIndicator.__options.text="Custom loading text"; busyIndicator.show(); }
每次调用busyIndicator.show()时调用showMyIndicator()。
busyIndicator.hide()可以正常调用(尽管你可能想要定义一些'hideMyIndicator()'函数来实现同质性)。
发生什么事?
看来,一旦我加载(jQuery $ .load())一些新内容以便更改页面,busyIndicator对象的文本fileld默认为“[(')هههههههههLoading]”,这是每个messages.json中的本机项目。 那个文件充满了那些奇怪的迹象,不知道为什么。
更新
我的项目中存在一些损坏,导致生成错误字符的.json文件,新生成的项目没有显示相同的问题,因此创建一个新的并移动资源可能会有效。
A workaround
define in some common .js file
function showMyIndicator() { busyIndicator.__options.text="Custom loading text"; busyIndicator.show(); }
and call showMyIndicator() each time you would call busyIndicator.show().
busyIndicator.hide() can be called normally (although you might want to define some 'hideMyIndicator()' function for homogeneity).
What is happening?
It appears that, as soon as I load (jQuery $.load() ) some new content in order to change page, the text fileld of the busyIndicator object defaults to "[(')ههههههه Loading]", which is defined in every native project inside messages.json. That file is full of those weird signs, no idea about why.
Update
There's something corrupted in my project which causes those .json files to be generated with wrong characters, a freshly generated project didn't show the same issues so creating a new one and move the resources in there might do the trick.
相关问答
更多-
更新:在最近的iFix中,默认适配器已更改为不再指向CNN。 如果还没有,请升级。 您的项目没有任何问题。 无论出于何种原因,似乎创建的默认适配器已停止使用CNN网站; 正在调查中。 同时,您可以使用来自不同项目的适配器(使用engadget网站),也可以创建自己的适配器。 例如,请参阅作为Starter Application示例的一部分提供的适配器(您可以将适配器文件夹复制到MobileFirst项目并使用“mfp push”将其部署到服务器;确保更新适配器和过程名称适用代码)。 Update: in ...
-
MobileFirst和Proguard(MobileFirst and Proguard)[2022-10-21]
是。 您可以将ProGuard与混合应用程序一起用于Android环境。 在这里阅读更多: https://developer.ibm.com/mobilefirstplatform/videos/ibm-mobilefirst-platform-foundation-android-proguard/ http://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.deploy.doc/admin/c_pg_obfu ... -
您必须实现WL.Badge API: http ://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.apiref.doc/html/refjavascript-client/html/WL 。 Badge.html?LANG = EN 你需要自己处理徽章...... You have to implement the WL.Badge API: http://www-01.ibm.com/support/knowl ...
-
尝试删除整个wlBuildResources folde。 此文件夹通常会被重新生成,因此也许还会重新生成缺失的资源。 Try to delete the entirety of the wlBuildResources folde. This folder typically gets regenerated so perhaps the missing resource will be regenerated as well.
-
如何在远程服务器中的ibm mobilefirst 7.1中添加运行时(how to add runtime in ibm mobilefirst 7.1 in remote server)[2023-07-17]
假设您有另一个MobileFirst项目,则需要使用IBM Configuration Tool来部署第二个.war文件。 它基本上遵循您对第一个.war文件所执行的相同步骤,仅部署不同的(.war)文件... 您也可以手动部署: http : //www.ibm.com/support/knowledgecenter/en/SSHS8R_7.1.0/com.ibm.worklight.deploy.doc/admin/c_manually_configuring_app_server.html Assum ... -
正如在MobileFirst中使用Cordova的教程中所写,目前你不能。 一定要仔细阅读。 https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/hello-world/integrating-mfpf-sdk-in-cordova-applications/ As written in the tutorial for using Cordova in MobileFirst, ...
-
这可以用MobileFirst 8.0吗? 我们可以针对MobileFirst 8.0服务器运行7.1个应用程序吗? 从文档中可以看出,您必须先将应用程序,项目和适配器从7.1迁移到8.0,然后才能在MobileFirst 8.0服务器上部署和运行它们。 没有向后兼容性。 在这里了解更多: 最新消息: https : //mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/product-overview/release-notes/wh ...
-
在最新的iFix版本中听起来像回归。 你知道演习 - 将要求PMR为你提供修复。 尝试重新启动服务器? Sounds like a regression in the latest iFix release. You know the drill - will require a PMR to provide you with a fix. Try restarting the server, though?
-
您不能使用已弃用的API或属性,因为我们可以随时决定完全删除它们,然后它将停止为您工作,您会抱怨它无法正常工作。 不要使用它。 You must not use deprecated APIs or properties, for the reason that we can decide to completely remove them at any moment, and then it'll stop working for you and you'll complain that it is no ...
-
MobileFirst 7.1 BusyIndicator显示奇怪的字符(MobileFirst 7.1 BusyIndicator showing weird characters)[2021-10-16]
解决方法 在一些常见的.js文件中定义 function showMyIndicator() { busyIndicator.__options.text="Custom loading text"; busyIndicator.show(); } 每次调用busyIndicator.show()时调用showMyIndicator()。 busyIndicator.hide()可以正常调用(尽管你可能想要定义一些'hideMyIndicator()'函数来实现同质性)。 发生什么事? 看 ...