Example usage for javax.swing JTextArea setOpaque

List of usage examples for javax.swing JTextArea setOpaque

Introduction

In this page you can find the example usage for javax.swing JTextArea setOpaque.

Prototype

@BeanProperty(expert = true, description = "The component's opacity")
public void setOpaque(boolean isOpaque) 

Source Link

Document

If true the component paints every pixel within its bounds.

Usage

From source file:Main.java

public static void main(String[] args) {
    JTextArea textArea = new JTextArea(5, 30);
    textArea.setOpaque(false);

    JViewport viewport = new JViewport() {
        @Override//from w  w  w. j a va2s .  c  o m
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            int w = this.getWidth();
            int h = this.getHeight();
            g.setColor(Color.RED);
            g.fillRect(0, 0, w / 2, h / 2);
        }
    };

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewport(viewport);
    scrollPane.setViewportView(textArea);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(scrollPane);
    frame.setLocationByPlatform(true);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

/**
 * Configures a text area to display as if it were a label.  This can be useful if you know how many columns
 * you want a label to be./*from w  ww  . j  a v a2 s .c o m*/
 * @param textArea The text area to configure as a JLabel.
 */
public static void configureAsLabel(JTextArea textArea) {
    textArea.setOpaque(false);
    Font textFont = UIManager.getFont("Label.font");
    textArea.setFont(textFont);
    textArea.setBorder(null);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setEditable(false);
}

From source file:Main.java

public static final Component getLabelComponent(String text, int rows, int cols) {
    JTextArea txt = new JTextArea(text, 10, 80);
    //txt.setColumns(80);
    txt.setWrapStyleWord(true);/*from w ww.  j a v a 2s. c o m*/
    txt.setLineWrap(true);
    txt.setOpaque(false);
    txt.setEditable(false);
    //txt.setEnabled(false);
    //txt.setFont(FontLoaderUtils.getOrLoadACompatibleFont(text,txt.getFont()));//UIManager.getFont("Label.font")));
    return new JScrollPane(txt);
}

From source file:Main.java

public static JScrollPane createScrollPane(JTextArea textArea, Font font, Color bgColor) {
    JScrollPane scrollPane = new JScrollPane(textArea);
    textArea.setLineWrap(true);//from   ww w .  jav a2  s .  c  om
    textArea.setWrapStyleWord(true);
    if (null != font) {
        textArea.setFont(font);
    }
    textArea.setOpaque(true);
    if (bgColor != null) {
        textArea.setBackground(bgColor);
    }

    return scrollPane;
}

From source file:com.heliosdecompiler.bootstrapper.Bootstrapper.java

private static HeliosData loadHelios() throws IOException {
    System.out.println("Finding Helios implementation");

    HeliosData data = new HeliosData();

    boolean needsToDownload = !IMPL_FILE.exists();
    if (!needsToDownload) {
        try (JarFile jarFile = new JarFile(IMPL_FILE)) {
            ZipEntry entry = jarFile.getEntry("META-INF/MANIFEST.MF");
            if (entry == null) {
                needsToDownload = true;// w w w. j  a  va 2 s.co  m
            } else {
                Manifest manifest = new Manifest(jarFile.getInputStream(entry));
                String ver = manifest.getMainAttributes().getValue("Implementation-Version");
                try {
                    data.buildNumber = Integer.parseInt(ver);
                    data.version = manifest.getMainAttributes().getValue("Version");
                    data.mainClass = manifest.getMainAttributes().getValue("Main-Class");
                } catch (NumberFormatException e) {
                    needsToDownload = true;
                }
            }
        } catch (IOException e) {
            needsToDownload = true;
        }
    }
    if (needsToDownload) {
        URL latestJar = new URL(LATEST_JAR);
        System.out.println("Downloading latest Helios implementation");

        FileOutputStream out = new FileOutputStream(IMPL_FILE);
        HttpURLConnection connection = (HttpURLConnection) latestJar.openConnection();
        if (connection.getResponseCode() == 200) {
            int contentLength = connection.getContentLength();
            if (contentLength > 0) {
                InputStream stream = connection.getInputStream();
                byte[] buffer = new byte[1024];
                int amnt;
                AtomicInteger total = new AtomicInteger();
                AtomicBoolean stop = new AtomicBoolean(false);

                Thread progressBar = new Thread() {
                    public void run() {
                        JPanel panel = new JPanel();
                        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

                        JLabel label = new JLabel();
                        label.setText("Downloading latest Helios build");
                        panel.add(label);

                        GridLayout layout = new GridLayout();
                        layout.setColumns(1);
                        layout.setRows(3);
                        panel.setLayout(layout);
                        JProgressBar pbar = new JProgressBar();
                        pbar.setMinimum(0);
                        pbar.setMaximum(100);
                        panel.add(pbar);

                        JTextArea textArea = new JTextArea(1, 3);
                        textArea.setOpaque(false);
                        textArea.setEditable(false);
                        textArea.setText("Downloaded 00.00MB/00.00MB");
                        panel.add(textArea);

                        JFrame frame = new JFrame();
                        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                        frame.setContentPane(panel);
                        frame.pack();
                        frame.setLocationRelativeTo(null);
                        frame.setVisible(true);

                        while (!stop.get()) {
                            SwingUtilities.invokeLater(
                                    () -> pbar.setValue((int) (100.0 * total.get() / contentLength)));

                            textArea.setText("Downloaded " + bytesToMeg(total.get()) + "MB/"
                                    + bytesToMeg(contentLength) + "MB");
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException ignored) {
                            }
                        }
                        frame.dispose();
                    }
                };
                progressBar.start();

                while ((amnt = stream.read(buffer)) != -1) {
                    out.write(buffer, 0, amnt);
                    total.addAndGet(amnt);
                }
                stop.set(true);
                return loadHelios();
            } else {
                throw new IOException("Content-Length set to " + connection.getContentLength());
            }
        } else if (connection.getResponseCode() == 404) { // Most likely bootstrapper is out of date
            throw new RuntimeException("Bootstrapper out of date!");
        } else {
            throw new IOException(connection.getResponseCode() + ": " + connection.getResponseMessage());
        }
    }

    return data;
}

From source file:de.unidue.inf.is.ezdl.gframedl.components.AboutDialog.java

private JPanel getContent() {
    JPanel panel = new JPanel(new GridBagLayout());

    JLabel iconLabel = new JLabel(new ImageIcon(Images.LOGO_EZDL_LARGE_SINGLE.getImage()));

    JTextArea licenseTextArea = new JTextArea(licenseText);
    licenseTextArea.setEditable(false);/*from ww  w .j  a v  a2 s . c o m*/
    licenseTextArea.setLineWrap(true);
    licenseTextArea.setWrapStyleWord(true);
    licenseTextArea.setOpaque(false);
    licenseTextArea.setBorder(BorderFactory.createEmptyBorder());
    JScrollPane licenseScrollPane = new JScrollPane(licenseTextArea);

    JTable propertiesTable = new JTable(tableModel);
    propertiesTable.setBackground(Color.WHITE);
    propertiesTable.setShowGrid(false);
    JScrollPane propertiesScrollPane = new JScrollPane(propertiesTable);
    propertiesScrollPane.setBackground(Color.WHITE);
    propertiesScrollPane.getViewport().setBackground(Color.WHITE);

    JButton closeButton = new JButton(I18nSupport.getInstance().getLocString("ezdl.controls.close"));
    closeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab(I18nSupport.getInstance().getLocString("ezdl.licence"), licenseScrollPane);
    tabbedPane.addTab(I18nSupport.getInstance().getLocString("ezdl.properties"), propertiesScrollPane);
    tabbedPane.setBackground(Color.WHITE);

    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(0, 0, 0, 0);
    c.anchor = GridBagConstraints.CENTER;
    panel.add(iconLabel, c);

    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 1;
    c.weighty = 1;
    c.anchor = GridBagConstraints.CENTER;
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(10, 20, 10, 20);
    panel.add(tabbedPane, c);

    c.gridy = 2;
    c.fill = GridBagConstraints.NONE;
    c.weighty = 0;
    c.insets = new Insets(0, 20, 10, 20);
    panel.add(closeButton, c);

    panel.setBackground(Color.WHITE);

    return panel;
}

From source file:com.smart.aqimonitor.client.AqiMonitor.java

/**
 * Create the frame.//w  w w  . jav  a  2  s . c o m
 */
public AqiMonitor() {
    refSelf = this;
    setPreferredSize(new Dimension(640, 480));
    setTitle("\u7A7A\u6C14\u8D28\u91CF\u76D1\u6D4B");
    setIconImage(Toolkit.getDefaultToolkit()
            .getImage(AqiMonitor.class.getResource("/lombok/installer/eclipse/STS.png")));
    setMinimumSize(new Dimension(640, 480));
    setMaximumSize(new Dimension(1024, 768));
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 636, 412);
    contentPane = new JPanel();
    contentPane.setPreferredSize(new Dimension(640, 480));
    contentPane.setMinimumSize(new Dimension(640, 480));
    contentPane.setMaximumSize(new Dimension(1024, 768));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);

    JPanel mainPanel = new JPanel();
    contentPane.add(mainPanel, BorderLayout.CENTER);
    mainPanel.setLayout(new BorderLayout(0, 0));

    JPanel contentPanel = new JPanel();
    mainPanel.add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));

    JScrollPane scrollPane = new JScrollPane();
    scrollPane
            .setViewportBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    contentPanel.add(scrollPane, BorderLayout.CENTER);

    textPane = new AqiTextPane();
    textPane.addInputMethodListener(new InputMethodListener() {

        public void caretPositionChanged(InputMethodEvent event) {

        }

        public void inputMethodTextChanged(InputMethodEvent event) {
            textPane.setCaretPosition(document.getLength() + 1);
        }
    });
    textPane.setEditable(false);
    textPane.setOpaque(false);
    textPane.setForeground(Color.BLACK);
    scrollPane.setViewportView(textPane);
    document = textPane.getStyledDocument();

    document.addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            if (e.getDocument() == document) {
                textPane.setCaretPosition(document.getLength());
            }
        }
    });

    JPanel buttonPanel = new JPanel();
    contentPane.add(buttonPanel, BorderLayout.SOUTH);
    buttonPanel.setLayout(new BorderLayout(0, 0));

    JLabel lblTipsLabel = new JLabel(
            "Tips\uFF1A\u6587\u4EF6\u4FDD\u5B58\u683C\u5F0Fcsv\u53EF\u7528Excel\u6253\u5F00");
    lblTipsLabel.setForeground(Color.BLUE);
    buttonPanel.add(lblTipsLabel, BorderLayout.WEST);

    JPanel panel = new JPanel();
    buttonPanel.add(panel, BorderLayout.CENTER);
    panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

    JButton btnRetrieve = new JButton("\u624B\u52A8\u83B7\u53D6\u6570\u636E");
    panel.add(btnRetrieve);
    btnRetrieve.setVerticalAlignment(SwingConstants.BOTTOM);

    JButton btnNewButton = new JButton("\u5173\u4E8E");
    btnNewButton.setToolTipText("\u5173\u4E8E");
    btnNewButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JTextArea textArea = new JTextArea(
                    "\n        csv\n\n        smartstudio@foxmail.com");
            textArea.setColumns(35);
            textArea.setRows(6);
            textArea.setLineWrap(true);// 
            textArea.setEditable(false);// 
            textArea.setOpaque(false);
            JOptionPane.showMessageDialog(contentPane, textArea, "", JOptionPane.PLAIN_MESSAGE);
        }
    });

    JButton btnSetting = new JButton("\u8BBE\u7F6E");
    btnSetting.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            Point parentPos = refSelf.getLocation();

            AqiSettingDialog settingDialog = new AqiSettingDialog(refSelf, pm25InDetailJob.getAqiParser());
            settingDialog.setModal(true);
            settingDialog.setLocation(parentPos.x + 100, parentPos.y + 150);
            settingDialog.init();
            settingDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            settingDialog.setVisible(true);
        }
    });

    JButton btnExportDir = new JButton("\u67E5\u770B\u6570\u636E");
    btnExportDir.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {

                String[] cmd = new String[5];

                String filePath = pm25InDetailJob.getAqiParser().getFilePath();
                File file = new File(filePath);
                if (!file.exists()) {
                    FileUtil.makeDir(file);
                }
                if (!file.isDirectory()) {
                    JOptionPane.showMessageDialog(contentPane, "", "",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }

                cmd[0] = "cmd";
                cmd[1] = "/c";
                cmd[2] = "start";
                cmd[3] = " ";
                cmd[4] = pm25InDetailJob.getAqiParser().getFilePath();

                Runtime.getRuntime().exec(cmd);

            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });
    panel.add(btnExportDir);
    panel.add(btnSetting);
    panel.add(btnNewButton);
    btnRetrieve.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (!isRetrieving) {
                isRetrieving = true;
                Thread firstRun = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        pm25InDetailJob.refresh();
                        isRetrieving = false;
                    }
                });

                firstRun.start();
            }
        }
    });

    init();
}

From source file:org.openmeetings.app.data.record.BatikMethods.java

public void drawTextByJTextArea(Graphics2D g2d, int x, int y, int width, int height, String text,
        String default_export_font, int style, int size, Color fontColor) throws Exception {

    //      g2d.setClip(x, y, width, height);
    //      g2d.setColor(Color.black);
    //      g2d.drawString(text, x, y+20);

    //Font font = new Font("Verdana", Font.PLAIN, 11);
    Font font = new Font(default_export_font, style, size);

    String[] stringsText = text.split("\r");
    //log.debug("TEXT: "+stringsText);
    //log.debug("TEXT: "+stringsText.length);

    String newText = "";

    for (int i = 0; i < stringsText.length; i++) {
        newText += stringsText[i];/*from  w w  w.ja v  a2 s.  co m*/
        if (i + 1 < stringsText.length) {
            newText += "\n";
        }
    }

    JTextArea n = new JTextArea(newText);
    n.setFont(font);
    n.setWrapStyleWord(true);
    n.setLineWrap(true);
    n.setForeground(fontColor);

    //log.debug("Text at: "+x+" "+y);
    //int x, int y, int width, int height
    n.setBounds(x, y, width, height);
    n.setOpaque(false);

    //Text
    SVGGraphics2D svgGenerator2 = (SVGGraphics2D) g2d.create(x, y, width, height);

    //svgGenerator2.create(x, y, width, height);
    //svgGenerator2.draw(.dra)
    n.paint(svgGenerator2);

}

From source file:ConfigFiles.java

public JPanel addPanel(String title, String description, final JTextField textfield, String fieldtext, int Y,
        boolean withbutton, ActionListener actionlistener) {
    JPanel p1 = new JPanel();
    p1.setBackground(Color.WHITE);
    TitledBorder border = BorderFactory.createTitledBorder(title);
    border.setTitleFont(new Font("Arial", Font.PLAIN, 14));
    border.setBorder(BorderFactory.createLineBorder(new Color(150, 150, 150), 1));
    p1.setBorder(border);/*www.  j  av  a  2 s  .c  om*/
    p1.setLayout(new BoxLayout(p1, BoxLayout.Y_AXIS));
    p1.setBounds(80, Y, 800, 75);
    paths.add(p1);
    JTextArea tcpath = new JTextArea(description);
    tcpath.setWrapStyleWord(true);
    tcpath.setLineWrap(true);
    tcpath.setEditable(false);
    tcpath.setCursor(null);
    tcpath.setOpaque(false);
    tcpath.setFocusable(false);
    tcpath.setFont(new Font("Arial", Font.PLAIN, 12));
    tcpath.setBackground(getBackground());
    tcpath.setMaximumSize(new Dimension(170, 22));
    tcpath.setPreferredSize(new Dimension(170, 22));
    tcpath.setBorder(null);
    JPanel p11 = new JPanel();
    p11.setBackground(Color.WHITE);
    p11.setLayout(new GridLayout());
    p11.add(tcpath);
    p11.setMaximumSize(new Dimension(700, 18));
    p11.setPreferredSize(new Dimension(700, 18));
    textfield.setMaximumSize(new Dimension(340, 27));
    textfield.setPreferredSize(new Dimension(340, 27));
    textfield.setText(fieldtext);
    JButton b = null;
    if (withbutton) {
        b = new JButton("...");
        if (!PermissionValidator.canChangeFWM()) {
            b.setEnabled(false);
        }
        b.setMaximumSize(new Dimension(50, 20));
        b.setPreferredSize(new Dimension(50, 20));
        if (actionlistener == null) {
            b.addActionListener(new AbstractAction() {
                public void actionPerformed(ActionEvent ev) {
                    Container c;

                    if (RunnerRepository.container != null)
                        c = RunnerRepository.container.getParent();
                    else
                        c = RunnerRepository.window;
                    try {
                        new MySftpBrowser(RunnerRepository.host, RunnerRepository.user,
                                RunnerRepository.password, textfield, c, false);
                    } catch (Exception e) {
                        System.out.println("There was a problem in opening sftp browser!");
                        e.printStackTrace();
                    }
                }
            });
        } else {
            b.addActionListener(actionlistener);
            b.setText("Save");
            b.setMaximumSize(new Dimension(70, 20));
            b.setPreferredSize(new Dimension(70, 20));
        }
    }
    JPanel p12 = new JPanel();
    p12.setBackground(Color.WHITE);
    p12.add(textfield);
    if (withbutton)
        p12.add(b);
    p12.setMaximumSize(new Dimension(700, 32));
    p12.setPreferredSize(new Dimension(700, 32));
    p1.add(p11);
    p1.add(p12);
    return p12;
}

From source file:edu.ku.brc.specify.plugins.ipadexporter.InstitutionConfigDlg.java

/**
 * @return//from  w w  w. j a  va 2s . c  om
 */
private JPanel createPicturePanel() {
    AppPreferences remotePrefs = AppPreferences.getRemote();

    String picturelocation = remotePrefs.get(getRemotePicturePrefName(), "");
    JTextArea explainTextArea = UIHelper.createTextArea();

    explainTextArea.setEditable(false);
    explainTextArea.setText(getResourceString("PICTURE_EXPLAIN"));
    explainTextArea.setOpaque(false);

    final String thumbnailPicMsg = getResourceString("THUMBNAIL_PIC");
    imageView = new ImageDisplay(200, 200, true, true);
    imageView.setThumbnailMsg(thumbnailPicMsg);

    if (StringUtils.isNotEmpty(picturelocation)) {
        String fullPath = UIRegistry.getAppDataDir() + File.separator + picturelocation;
        File urlFile = new File(fullPath);
        if (urlFile.exists()) {
            imageView.setValue(urlFile.toURI().toASCIIString(), null);
        }
    }

    JButton clearBtn = UIHelper.createI18NButton("CLEAR_PICTURE");
    clearBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            imageView.setValue(null, null);
            imageView.setThumbnailMsg(thumbnailPicMsg);
            imageView.repaint();
        }
    });
    CellConstraints cc = new CellConstraints();

    PanelBuilder epb = new PanelBuilder(new FormLayout("f:p:g", "top:p:g,4px,p"));
    epb.add(explainTextArea, cc.xy(1, 1));

    PanelBuilder bpb = new PanelBuilder(new FormLayout("p", "f:p:g,p"));
    bpb.add(clearBtn, cc.xy(1, 2));
    epb.add(bpb.getPanel(), cc.xy(1, 3));

    PanelBuilder pb = new PanelBuilder(new FormLayout("p,8px,f:p:g", "f:p:g"));
    pb.add(imageView, cc.xy(1, 1));
    pb.add(epb.getPanel(), cc.xy(3, 1));

    return pb.getPanel();
}