List of usage examples for javax.swing JTextArea setSize
public void setSize(int width, int height)
From source file:Main.java
public static void main(String[] args) { String text = "one two three four five six seven eight nine ten "; JTextArea textArea = new JTextArea(text); textArea.setColumns(30);//w ww. ja v a 2s . co m textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.append(text); textArea.append(text); textArea.append(text); textArea.append(text); textArea.append(text); textArea.setSize(textArea.getPreferredSize().width, 1); JOptionPane.showMessageDialog(null, new JScrollPane(textArea), "Not Truncated!", JOptionPane.WARNING_MESSAGE); }
From source file:com.edduarte.protbox.Protbox.java
public static void main(String... args) { // activate debug / verbose mode if (args.length != 0) { List<String> argsList = Arrays.asList(args); if (argsList.contains("-v")) { Constants.verbose = true;/* w ww .ja va2s .com*/ } } // use System's look and feel try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { // If the System's look and feel is not obtainable, continue execution with JRE look and feel } // check this is a single instance try { new ServerSocket(1882); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Another instance of Protbox is already running.\n" + "Please close the other instance first.", "Protbox already running", JOptionPane.ERROR_MESSAGE); System.exit(1); } // check if System Tray is supported by this operative system if (!SystemTray.isSupported()) { JOptionPane.showMessageDialog(null, "Your operative system does not support system tray functionality.\n" + "Please try running Protbox on another operative system.", "System tray not supported", JOptionPane.ERROR_MESSAGE); System.exit(1); } // add PKCS11 providers FileFilter fileFilter = new AndFileFilter(new WildcardFileFilter(Lists.newArrayList("*.config")), HiddenFileFilter.VISIBLE); File[] providersConfigFiles = new File(Constants.PROVIDERS_DIR).listFiles(fileFilter); if (providersConfigFiles != null) { for (File f : providersConfigFiles) { try { List<String> lines = FileUtils.readLines(f); String aliasLine = lines.stream().filter(line -> line.contains("alias")).findFirst().get(); lines.remove(aliasLine); String alias = aliasLine.split("=")[1].trim(); StringBuilder sb = new StringBuilder(); for (String s : lines) { sb.append(s); sb.append("\n"); } Provider p = new SunPKCS11(new ReaderInputStream(new StringReader(sb.toString()))); Security.addProvider(p); pkcs11Providers.put(p.getName(), alias); } catch (IOException | ProviderException ex) { if (ex.getMessage().equals("Initialization failed")) { ex.printStackTrace(); String s = "The following error occurred:\n" + ex.getCause().getMessage() + "\n\nIn addition, make sure you have " + "an available smart card reader connected before opening the application."; JTextArea textArea = new JTextArea(s); textArea.setColumns(60); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.setSize(textArea.getPreferredSize().width, 1); JOptionPane.showMessageDialog(null, textArea, "Error loading PKCS11 provider", JOptionPane.ERROR_MESSAGE); System.exit(1); } else { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "Error while setting up PKCS11 provider from configuration file " + f.getName() + ".\n" + ex.getMessage(), "Error loading PKCS11 provider", JOptionPane.ERROR_MESSAGE); } } } } // adds a shutdown hook to save instantiated directories into files when the application is being closed Runtime.getRuntime().addShutdownHook(new Thread(Protbox::exit)); // get system tray and run tray applet tray = SystemTray.getSystemTray(); SwingUtilities.invokeLater(() -> { if (Constants.verbose) { logger.info("Starting application"); } //Start a new TrayApplet object trayApplet = TrayApplet.getInstance(); }); // prompts the user to choose which provider to use ProviderListWindow.showWindow(Protbox.pkcs11Providers.keySet(), providerName -> { // loads eID token eIDTokenLoadingWindow.showPrompt(providerName, (returnedUser, returnedCertificateData) -> { user = returnedUser; certificateData = returnedCertificateData; // gets a password to use on the saved registry files (for loading and saving) final AtomicReference<Consumer<SecretKey>> consumerHolder = new AtomicReference<>(null); consumerHolder.set(password -> { registriesPasswordKey = password; try { // if there are serialized files, load them if they can be decoded by this user's private key final List<SavedRegistry> serializedDirectories = new ArrayList<>(); if (Constants.verbose) { logger.info("Reading serialized registry files..."); } File[] registryFileList = new File(Constants.REGISTRIES_DIR).listFiles(); if (registryFileList != null) { for (File f : registryFileList) { if (f.isFile()) { byte[] data = FileUtils.readFileToByteArray(f); try { Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, registriesPasswordKey); byte[] registryDecryptedData = cipher.doFinal(data); serializedDirectories.add(new SavedRegistry(f, registryDecryptedData)); } catch (GeneralSecurityException ex) { if (Constants.verbose) { logger.info("Inserted Password does not correspond to " + f.getName()); } } } } } // if there were no serialized directories, show NewDirectory window to configure the first folder if (serializedDirectories.isEmpty() || registryFileList == null) { if (Constants.verbose) { logger.info("No registry files were found: running app as first time!"); } NewRegistryWindow.start(true); } else { // there were serialized directories loadRegistry(serializedDirectories); trayApplet.repaint(); showTrayApplet(); } } catch (AWTException | IOException | GeneralSecurityException | ReflectiveOperationException | ProtboxException ex) { JOptionPane.showMessageDialog(null, "The inserted password was invalid! Please try another one!", "Invalid password!", JOptionPane.ERROR_MESSAGE); insertPassword(consumerHolder.get()); } }); insertPassword(consumerHolder.get()); }); }); }
From source file:Form.Principal.java
public void PanelClientes() { int i = 0;/*from w w w . j a va 2s . c om*/ int Altura = 0; Color gris = new Color(44, 44, 44); Color rojo = new Color(221, 76, 76); Color azul = new Color(0, 153, 255); try { //Consultamos todos los clientes ResultSet Comandos = Funcion.Select(st, "SELECT * FROM cliente;"); //Ciclo para crear un panel para cada uno while (Comandos.next()) { //Creamos un panel con alineacion a la izquierda JPanel Panel = new JPanel(); Panel.setLayout(null); jPanel8.add(Panel); //Tamao del panel Panel.setSize(700, 195); // La posicion y del panel ira incrementando para que no se encimen Altura = 30 + (i * 205); Panel.setLocation(50, Altura); Panel.setBackground(Color.white); Panel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); //Creamos label para mostrar los datos del cliente, el codigo html es para que al llegar al final del panel //se pase a la siguiente linea y para el margen izquierdo JLabel RFC = new JLabel(); RFC.setText("RFC: " + Comandos.getString("RFC")); JLabel Nombre = new JLabel(); Nombre.setText("Nombre: " + Comandos.getString("NombreCliente")); JTextArea Direccion = new JTextArea(); Direccion.setLineWrap(true); Direccion.setBorder(null); Direccion.setText("Direccin: " + Comandos.getString("Direccion")); JLabel Correo = new JLabel(); Correo.setText("Correo: " + Comandos.getString("correo")); JButton VerMas = new JButton(); VerMas.setText("Ver ms"); VerMas.setName(Comandos.getString("idCliente")); VerMas.setBackground(azul); JButton Eliminar = new JButton(); Eliminar.setText("Eliminar"); Eliminar.setName(Comandos.getString("idCliente")); Eliminar.setBackground(rojo); MouseListener mlVerMas = new MouseListener() { @Override public void mouseReleased(MouseEvent e) { //System.out.println("Released!"); } @Override public void mousePressed(MouseEvent e) { //System.out.println("Pressed!"); } @Override public void mouseExited(MouseEvent e) { //System.out.println("Exited!"); } @Override public void mouseEntered(MouseEvent e) { //System.out.println("Entered!"); e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } @Override public void mouseClicked(MouseEvent e) { JButton source = (JButton) e.getSource(); id = Integer.parseInt(source.getName()); jTabbedPane2.setSelectedIndex(4); jButton16.setVisible(true); jButton17.setVisible(true); jButtonEditar.setVisible(true); jPanel9.setVisible(true); jPanel10.setVisible(true); jPanel14.setVisible(false); LlenarPanel(); } }; VerMas.addMouseListener(mlVerMas); MouseListener mlEliminar = new MouseListener() { @Override public void mouseReleased(MouseEvent e) { //System.out.println("Released!"); } @Override public void mousePressed(MouseEvent e) { //System.out.println("Pressed!"); } @Override public void mouseExited(MouseEvent e) { //System.out.println("Exited!"); } @Override public void mouseEntered(MouseEvent e) { //System.out.println("Entered!"); e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } @Override public void mouseClicked(MouseEvent e) { JButton source = (JButton) e.getSource(); Funcion.Update(st, "DELETE FROM cliente WHERE idCliente = " + source.getName() + ";"); Autocompletar.removeAllItems(); Autocompletar = new TextAutoCompleter(jTextField2); ResultSet Comandos = Funcion.Select(st, "SELECT * FROM cliente;"); try { while (Comandos.next()) { Autocompletar.addItem(Comandos.getString("RFC")); } } catch (SQLException ex) { //Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex); } jPanel8.removeAll(); PanelClientes(); jPanel8.repaint(); } }; Eliminar.addMouseListener(mlEliminar); //Fuente del texto RFC.setFont(new Font("Verdana", Font.PLAIN, 14)); RFC.setForeground(gris); Nombre.setFont(new Font("Verdana", Font.PLAIN, 14)); Nombre.setForeground(gris); Direccion.setFont(new Font("Verdana", Font.PLAIN, 14)); Direccion.setForeground(gris); Correo.setFont(new Font("Verdana", Font.PLAIN, 14)); Correo.setForeground(gris); VerMas.setFont(new Font("Verdana", Font.PLAIN, 14)); VerMas.setForeground(Color.white); Eliminar.setFont(new Font("Verdana", Font.PLAIN, 14)); Eliminar.setForeground(Color.white); /*VERMAS.setFont(new Font("Verdana", Font.PLAIN, 13)); VERMAS.setForeground(azul);*/ //Aadimos los label al panel correspondiente del cliente Panel.add(RFC); Panel.add(Nombre); Panel.add(Direccion); Panel.add(Correo); Panel.add(VerMas); Panel.add(Eliminar); RFC.setLocation(30, 10); RFC.setSize(610, 30); Nombre.setLocation(30, 40); Nombre.setSize(610, 30); Direccion.setLocation(30, 75); Direccion.setSize(610, 40); Correo.setLocation(30, 115); Correo.setSize(610, 30); VerMas.setLocation(210, 150); VerMas.setSize(120, 35); Eliminar.setLocation(390, 150); Eliminar.setSize(120, 35); //Panel.add(VERMAS); i++; } } catch (SQLException ex) { Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex); } //Dependiendo de cuantos clientes se agregaron, se ajusta el tamao del panel principal para que el scroll llegue hasta ahi jPanel8.setPreferredSize(new Dimension(jPanel8.getWidth(), Altura + 205)); }