小编Lit*_*ild的帖子

无法在JWindow中的JPanel内编辑JTextField的文本

在此输入图像描述

这是我之前的问题的继续,我问如何在系统托盘中放置一些东西.
在社区的一些帮助下,我可以做到这一点.但是什么我不能做的是改变的文本JTextFieldJWindow.

JWindowJPanel,一切都置于内JPanel,包括JTextField提醒百万吨.但是,即使我无法输入任何内容setEditable(true).
JTextField,因为它应该是白色的,当鼠标进入和返回时鼠标退出到默认的颜色正确地接收事件.

这有什么解决方法吗?


SSCCE

package demo;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.InputStream;

import javax.imageio.ImageIO;
import javax.sound.sampled.*;
import javax.swing.*;
import javax.swing.border.BevelBorder;

import example.Kernel32;

public class SSCCE {
    JPopupMenu popup = new JPopupMenu();
    JMenuItem exit = new JMenuItem("Exit");

    JWindow window = new JWindow();
    JPanel panel = new JPanel();
    int remindMeAt = 55;
    Kernel32.SYSTEM_POWER_STATUS batteryStatus = new Kernel32.SYSTEM_POWER_STATUS();

    Clip buzzer;
    AudioInputStream …
Run Code Online (Sandbox Code Playgroud)

java swing jtextfield jwindow

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

单击侦听器上的通知RemoteView

因此,在经过大量的努力之后,我才结束了.我的RemoteViews通知中有一个媒体播放器,我希望能够访问播放,暂停,上一个和下一个按钮.

我知道setOnClickPendingIntent()将用于通知通知.但是,我想知道它是如何工作的.

是否可以让服务处理点击?

我试过这个,但是徒劳无功.我试图让我服务处理播放器的暂停和恢复:

rm = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notif_media_player);

        Intent intent = new Intent(getApplicationContext(), MusicService.class);
        intent.putExtra(REQUEST_CODE, PAUSE);
        PendingIntent pending = PendingIntent.getService(getApplicationContext(), PAUSE, intent, 0);
        rm.setPendingIntentTemplate(R.id.pause, pending);

        Notification notif =  new NotificationCompat.Builder(getApplicationContext())
                                 .setOngoing(true)
                                 .setSmallIcon(R.drawable.ic_launcher)
                                 .setContent(rm)
                                 .build();

        NotificationManager mgr = (NotificationManager) getApplicationContext()
                                  .getSystemService(Context.NOTIFICATION_SERVICE);
        mgr.notify(NOTIFICATION_ID, notif);  
Run Code Online (Sandbox Code Playgroud)

我的IBinder是空的.如果这有所作为.

如何从通知中暂停和播放音乐?

android android-service android-pendingintent android-remoteview

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

如何找到手机的密度桶?

稍微有点noob-ish问题,但在计算手机密度桶的时候我感到很困惑.我将把我的Galaxy S3作为一个例子.

它的分辨率1280 x 720意味着它具有306 dpi.现在,参考下面的图表,我的手机属于该hdpi类别,因为它的屏幕数量240 dpi超过了320 dpi所需数量xhdpi.所以,手机是853 x 480 DP(除以1.5)

但是,我手机上的屏幕信息应用程序告诉我它是一个xhdpi屏幕.所以,手机是640 x 360 DP(除以2).

我怎么知道手机的密度桶是什么?

在此输入图像描述

更新:
我正在尝试为我所在国家/地区的前10款Android手机设计我的应用.因此,我正在计算他们在DP中的大小,以根据他们的"最小宽度DP"设计UI.这不是一次性的大小计算.

android screen dpi density-independent-pixel

4
推荐指数
3
解决办法
1998
查看次数

添加动画GIF到摇摆标签

public void run(){
        Icon reel = common.ResourcesToAccess.reel;
        JLabel label = new JLabel(reel);
        JFrame frame = new JFrame();
        frame.setUndecorated(true);
        frame.getContentPane().add(label);
        frame.setSize(reel.getIconWidth(),reel.getIconHeight());
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        try{
            sleep(2*1000);
        }catch(InterruptedException e){

        }
        frame.dispose();
    }  
Run Code Online (Sandbox Code Playgroud)

我尝试键入reel.setImageObserver(label);但Eclipse将该语句标记为错误.为什么?
我还能做些什么来展示动画?



更新:新代码:

@Override
    public void run(){
        JFrame f = new JFrame();
        ImageIcon reel = (ImageIcon) common.ResourcesToAccess.reel;
        JLabel label = new JLabel(reel);
        reel.setImageObserver(label);
        f.getContentPane().add(label);
        f.setUndecorated(true);
        f.setSize(300, 300);
        f.setVisible(true);
    }  
Run Code Online (Sandbox Code Playgroud)

虽然我可以在这里设置ImageObserver,但GIF仍然没有动画

其他:

我正在使用的GIF可以在这里找到:
http://bestanimations.com/Electronics/Video/Video.html
这是右边电视上方的那个.旋转卷轴.

java animation swing jlabel jframe

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

如何将东西添加到系统托盘并添加mouseOver()功能?

在此输入图像描述

对不起,如果标题含糊不清,但这正是我想要实现的.
这是Battery Care软件图标化/最小化.将鼠标悬停在图标上时,您将看到图片中显示的窗口.
如何在Java中实现?

java swing system-tray mouseover mouseevent

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

如何确定系统托盘在屏幕上的位置?

所以我想JPopupMenu在用户单击系统托盘中的图标时显示.但是,任务栏可以位于屏幕上的任何位置 - 底部,顶部,右侧,左侧.

在此输入图像描述

如何确定sys托盘的位置以便显示弹出窗口?
getX()getY()可以获得点击的坐标.可以做一些数学运算来正确显示弹出窗口吗?

一个简单的解释和示例代码将不胜感激.

此外,如果任务栏被隐藏,当我添加TrayIconSystemTray?时会生成异常吗?

java

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

cvc-complex-type.3.2.2:属性xsi:不允许schemaLocation出现在Java DOM中的<people>中

我试图通过使用DOM验证器在Java中使用XSD验证我的XML.
虽然我手动地知道该文档确实有效,但DOM验证器还是对我说:

cvc-complex-type.3.2.2: Attribute <xsi:schemaLocation> is not allowed to appear in the element <people>  
Run Code Online (Sandbox Code Playgroud)

我已经确定的是:
setNamespaceAware()被设置为true
schemaLanguage是之前设置属性schemaSource
schemaLanguage设置为http://ww.w3.org/2001/XMLSchema
两者的XSDXML在同一个文件夹中.java.class文件

SSCCE

import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.parsers.*;

public class DOMValidator {
    String xmlInstance = null;
    String xmlSchema = null;


    public static void main(String[] args){
        DOMValidator validator = new DOMValidator();
        validator.validateXML("student.xsd",
                              "helloWorld.xml");
    }

    public void validateXML(String xsd,String xml){
        xmlSchema = xsd;
        xmlInstance = xml;
        beginValidation();
    }

    public …
Run Code Online (Sandbox Code Playgroud)

java xml dom jaxp saxparseexception

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

由于URI无效,安装失败

[2013-07-21 11:14:01 - AndroidTrial] Installation failed due to invalid URI!
[2013-07-21 11:14:01 - AndroidTrial] Please check logcat output for more details.
[2013-07-21 11:14:02 - AndroidTrial] Launch canceled!  
Run Code Online (Sandbox Code Playgroud)

这是我尝试运行试验项目时得到的结果.logcat中没有输出.
我在SO上查看了其他类似问题的答案,他们说这可能是因为重音字符.我没有这些.

这是我的简单代码:

public class HaikuDisplay extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void onTrialButtonClicked(View view){
        TextView v = (TextView) findViewById(R.id.text);
        v.setVisibility(View.VISIBLE);
    }

}  
Run Code Online (Sandbox Code Playgroud)

这是XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".HaikuDisplay" >
    <Button 
        android:id="@+id/topBtn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/love_button_text"
        android:onClick="onTrialButtonClicked"
        />
    <TextView
        android:layout_below="@id/topBtn"
        android:id="@+id/text"
        android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

java eclipse android

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

ThreadPoolExecutor中的核心线程是什么?

我正在查看ThreadPoolExecutor该类,我发现它允许指定最大池大小和核心池大小.

我有点了解何时根据这里的答案更改核心和最大池大小:何时在ThreadPoolExecutor中指定单独的核心和最大池大小是一个好主意?

但是,我想知道这些"核心线程"是什么.当我使用a的getCorePoolSize()方法时,我总是得到0ThreadPoolExecutor

SSCCE在这里:

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

public class PoolSize {
    public static void main(String[] args) {
        // Create a cached thread pool
        ExecutorService cachedPool = Executors.newCachedThreadPool();
        // Cast the object to its class type
        ThreadPoolExecutor pool = (ThreadPoolExecutor) cachedPool;

        // Create a Callable object of anonymous class
        Callable<String> aCallable = new Callable<String>(){
            String result = "Callable done !";
            @Override
            public String call() throws Exception {
                // …
Run Code Online (Sandbox Code Playgroud)

java multithreading threadpoolexecutor

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

ElasticSearch 将多个字段视为模糊查询

{
    "title" : "That Uselessly Amazing Title",
    "author" : "Someone you have never heard of",
    "url" : "http://www.theuselessweb.com",
    "summary" : "a collection of useless websites",
    "tag" : ["useless","maybe useful"]
}  
Run Code Online (Sandbox Code Playgroud)

假设我有一个类似于上面所示的架构。用户要求应用程序显示一些“无用”的内容。

如何编写一个查询,通过标题、摘要和标签来查找“无用”一词作为模糊搜索?

lucene elasticsearch

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