小编lsc*_*hin的帖子

简单地将JLabel添加到JPanel

我有一个简单的问题,因为我对Java GUI不太熟悉.我试图在下面的代码中看到JLable,因为我发现很难理解这个概念.但仍然看不到标签,但框架在运行时打开.

public class Sample extends JPanel {

    public void Sample() {
        JPanel p = new JPanel();

        JLabel lab1 = new JLabel("User Name", JLabel.LEFT);
        p.setLayout(new FlowLayout());
        p.add(lab1 = new JLabel("add JLabel"));
    }

    public static void main(String[] args) {

        JFrame frame = new JFrame();
        frame.getContentPane().add(new Sample());

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(200, 200);
        frame.setVisible(true);
    }
}
Run Code Online (Sandbox Code Playgroud)

java swing

4
推荐指数
1
解决办法
7万
查看次数

如何删除Struts 1.3的显示标签中未显示的内容

我想删除没有找到Struts 1.3显示标记中显示的消息,当没有从数据库中获取记录时.

它有可能做到这一点......?

struts displaytag

4
推荐指数
1
解决办法
8793
查看次数

Struts2:如何在select标签中显示每个下拉选项的工具提示?

我有这个struts2 select标签,其中的选项是Item对象的列表.假设Item java bean类具有以下3个属性:itemId, itemLabel, itemDescription.

我的选择标签看起来像这样:

<s:select headerKey="" 
  headerValue="Select Item"
  list="myModel.itemsList"
  listKey="itemId"
  listValue="itemLabel"
  name="selectedItem" />   
Run Code Online (Sandbox Code Playgroud)

我希望每当用户使用该选项时,在下拉菜单中显示每个选项的工具提示.填充该工具提示的文本存储在itemDescription我的java bean类的属性中

我知道你可以为select标签提供一个tooptip,但这不是我需要的,因为每个选项/项目都有不同的描述.

目前我有一个自定义的javascript工具提示,如果可能的话我想使用这个功能.如果项目将列在表格中,我将使用该函数:

<td>
    <span class="tooltip" onmouseout="tooltip.hide();"
      onmouseover="tooltip.show('<s:property value="item.description" />');">
        <s:property value="item.label" />
    </span>
</td>
Run Code Online (Sandbox Code Playgroud)

有没有人知道什么是最好的解决方案,description每当用户将鼠标悬停在选项上时显示为工具提示?

select struts2 tooltip

4
推荐指数
1
解决办法
1万
查看次数

使用jodatime查找剩余的日期和时间

我想用joda时间比较(找出两天之间的剩余天数和时间).我正在采取两个这样的DateTime对象(一个正在启动而另一个正在结束)

DateTime endDate  = new DateTime(2011,12,25,0,0,0,0);   
DateTime strtDate = new DateTime();
Run Code Online (Sandbox Code Playgroud)

现在我有兴趣找到这样的剩余日期和时间 days:49 Hrs:5 Min:52 Sec:45(不考虑这里的年份和月份..)

现在我像这样继续上课

Period period = new Period();

PeriodFormatter formatter = new PeriodFormatterBuilder()
    .appendSeconds()
    .appendMinutes()
    .appendHours()
    .appendDays()
    .appendMonths()
    .appendYears()
    .printZeroNever()
    .toFormatter();
Run Code Online (Sandbox Code Playgroud)

现在结果是我得到年,月,日等...在这种情况下,我将得到之间的日子1-30(不是31,45,49 ...(我想要)).

那么我怎么能得到这个东西(有没有我缺少的方法)或者我需要以编程方式处理这个,因为我读到joda时间非常灵活所以我非常确定会有这样的方法.

如果您熟悉,那么请分享您的知识.

java android jodatime

4
推荐指数
1
解决办法
3491
查看次数

Junit类 - 无法加载ApplicationContext

我正在研究Spring Framework.并制作了一个junit类,但我无法正确加载在junit类中运行@Test方法所需的xml文件.就我而言

  • xml文件放在文件夹下 WEB-INF
  • junit测试类是在 test/<package_name>

请建议我正确声明xml文件的方法

@ContextConfiguration

@ContextConfiguration( locations={ "classpath:/applicationContext.xml",
        "classpath:/applicationDatabaseContext.xml" })
Run Code Online (Sandbox Code Playgroud)

错误:

允许TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@48fa48fa]准备测试实例[]时出现异常java.lang.IllegalStateException:无法加载ApplicationContext

java junit spring

4
推荐指数
1
解决办法
2万
查看次数

资源不可用的问题

我收到HTTP状态404 - 请求的资源(/ Fun/hello)不可用.
我正在运行Tomcat 7.0,Jersey 1.8,Java 1.6,Eclipse Helios 2.
我正在使用Lars Vogel的教程.

据我所知,资源正在加载:

INFO: Root resource classes found:
  class bighello.Hello
Run Code Online (Sandbox Code Playgroud)

web.xml中

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee                       http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 
  <display-name>Fun</display-name>
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>bighello</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>

</web-app>
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

eclipse tomcat jersey

3
推荐指数
1
解决办法
2708
查看次数

Struts2使用某个表达式禁用<s:textfield>

我在我的应用程序中有两个角色,ROLE_ADMIN和ROLE_USER我还有一个带有一些字段的表单.我想拥有以下内容:当用户具有ADMIN角色时,他能够编辑特定的字段组,当用户具有USER角色时,他无法编辑这些字段.我不想为每个角色提供两种不同的形式或两个字段副本.

我试着这样做:

<s:textfield key ="..." disabled ="$ {myFlag}" >,其中myFlag从角色评估.

但我警告"禁用"不支持运行时表达式.

有没有办法做到这一点?或者可能有更好的方法,例如,将生成的输入替换为标签?

提前致谢.

jsp expression struts2

3
推荐指数
1
解决办法
2万
查看次数

Grails 2.0.4打开zip文件或JAR清单错误Springloaded时出错

我刚刚下载了Grails 2.0.4并将其解压缩到/opt/grails/grails-2.0.4/并确保GRAILS_HOME环境变量是正确的.但每当我尝试运行"grails"命令时,我都会收到以下错误:

Error opening zip file or JAR manifest missing : /opt/grails/grails-2.0.4/lib/com.springsource.springloaded/springloaded-core/jars/springloaded-core-1.0.2.jar
Error occurred during initialization of VM
agent library failed to init: instrument
Run Code Online (Sandbox Code Playgroud)

我不明白问题是什么.几个月来,我一直在Grails-2.0.1中以完全相同的方式成功使用Grails-2.0.1.我已经尝试重新下载grails-2.0.4.zip文件,希望它是存档的问题,但这没有帮助.我还从grails-2.0.1 /目录复制了springloaded-core-1.0.2.jar,但这只是导致了另一组错误.

什么可能出错?

java grails spring spring-loaded

3
推荐指数
2
解决办法
1万
查看次数

struts 2教程中的第一个例子

我想开始使用Struts 2框架,我下载Struts 2.2.3 ,并按照本教程 制作第一个例子,但是当我运行index.jsp时

<%@ taglib prefix="s"  uri="/struts-tags" %>
 ....
<p><a href="<s:url action='hello'/>">Hello World</a></p>
..
Run Code Online (Sandbox Code Playgroud)

发生此异常:

org.apache.jasper.JasperException: The Struts dispatcher cannot be found.  This is usually       caused by using Struts tags without the associated filter. Struts tags are only usable when the  request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
Run Code Online (Sandbox Code Playgroud)

我没有在web.xml中指定任何过滤器,因为在创建Web应用程序时没有创建web.xml文件?只存在sun-web.xml文件.

java jsp struts2

1
推荐指数
1
解决办法
4478
查看次数

如何读取类中的全局属性文件?

我正在阅读以下网址上的struts2教程.

http://struts.apache.org/2.2.1/docs/message-resource-files.html

它解释了如何读取视图文件中属性键的值,但它没有解释如何读取操作类或模型类中的属性值.

如何在动作或模型类中读取属性键的值?

java struts2 internationalization

1
推荐指数
1
解决办法
4845
查看次数