小编Pin*_*no 的帖子

如何避免在以特定符号[java]开头的行中突出显示字符串

我正在制作一个文本编辑器,它在文本的第一行中找到一个字符串,并在整个文本中突出显示它.问题是它还突出显示位于注释行中的事件(以"#"开头).到目前为止这是我的代码:

    import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;

import java.awt.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class TextArea {

    public static void main(String[] args) {
        JFrame frame = new JFrame("textArea");
        frame.setSize(500,500);

        final JTextArea textArea = new JTextArea() ;
        frame.add(textArea);

        frame.setVisible(true);

        textArea.getDocument().addDocumentListener(new DocumentListener(){

            @Override
            public void changedUpdate(DocumentEvent e) {
                try {
                    String keyWords = findKeyWord();
                    findOccurrences(keyWords);
                } catch (BadLocationException ex) {
                    Logger.getLogger(TextArea.class.getName()).log(Level.SEVERE, null, ex);
                }

            }

            @Override
            public void insertUpdate(DocumentEvent e) {
                try { …
Run Code Online (Sandbox Code Playgroud)

java swing highlight jtextarea

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

触摸在外面时,AlertDialog消失[Android]

我在我的应用程序上使用警报对话框,但当用户触摸它时它会一直隐藏.这是我的代码:

public class DialogMessageEnd extends DialogFragment
{
    String winner;

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the Builder class for convenient dialog construction
        Snooker_Scoreboard ss = new Snooker_Scoreboard();
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setCancelable(false);
        builder.setMessage(ss.winnerPlayer + " won the match ("+ss.frame1ToPass+"-"+ss.frame2ToPass+")!")
                .setPositiveButton("New Match!", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Intent i = new Intent(getContext(),PlayerSelection.class);
                        startActivity(i);
                    }
                });



        // Create the AlertDialog object and return it
        return builder.create();
    }

}
Run Code Online (Sandbox Code Playgroud)

如你所见,我用过

builder.setCancelable(false);
Run Code Online (Sandbox Code Playgroud)

但它仍然无法解决问题.你能帮助我吗?谢谢

java android android-alertdialog

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

交换ndarray的列

我试图从2d数组交换两列,这样

a = array([[1, 2, 3],
           [4, 5, 6],
           [7, 8, 9]])
Run Code Online (Sandbox Code Playgroud)

变为:

b = array([[1, 3, 2],
           [4, 6, 5],
           [7, 9, 8]])
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

python numpy multidimensional-array

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