Java – checking if parseInt throws exception
public static boolean isParsable(String input) { try { Integer.parseInt(input); return true; } catch (final NumberFormatException e) { return false; } }
public static boolean isParsable(String input) { try { Integer.parseInt(input); return true; } catch (final NumberFormatException e) { return false; } }
You should use JScrollPane#setRowHeaderView to set the component that will appear at the left hand side of the scroll pane. The benefit of this is the row header won’t scroll to the left as the view scrolls to the right… The example deliberately uses line wrapping… import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.FontMetrics; import … Read more
How to set AUTO-SCROLLING of JTextArea in Java GUI? http://download.oracle.com/javase/1.5.0/docs/api/javax/swing/text/DefaultCaret.html#NEVER_UPDATE Try: JTextArea textArea = new JTextArea(); DefaultCaret caret = (DefaultCaret)textArea.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); This should prevent the caret from automatically making the document scroll to the bottom.
Okay, so this is my idea… The basic idea is we want to keep track of “user” input and “process” output. Basically what I’ve done is set it up so that when the process terminates, we calculate the current position of the caret in the document and mark that as the start position of the … Read more
The main problem you’re having is you’re trying to perform blocking actions in the Event Dispatching Thread. This will prevent the UI from been updated as repaint requests are not reaching the repaint manager until AFTER you’ve finished. To over come this, you’re going to need to off load the blocking work (ie the back … Read more
Here try this small program, try to click at the start of student://, that will pop up a message Dialog import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TextAreaExample extends JFrame { private JTextArea tarea = new JTextArea(10, 10); private JTextField tfield = new JTextField(10); private void createAndDisplayGUI() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tarea.setText(“Hello there\n”); tarea.append(“Hello student://”); JScrollPane … Read more
You can achieve this, though not directly, since you have to save the reference to the Highlight that you had added to the said line, hence you have to traverse through all the Highlights to remove the one you want, have a look at the program attached, might be this will help you to attain … Read more
Use a custom border that extends AbstractBorder. Something like this: Getting the exact shape & color is left as an exercise for the reader. 🙂 import java.awt.*; import java.awt.geom.*; import javax.swing.*; import javax.swing.border.AbstractBorder; class TextBubbleBorder extends AbstractBorder { private Color color; private int thickness = 4; private int radii = 8; private int pointerSize = … Read more
and the scrollbar will be on the left scrollPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); so the text inside it will start from the right textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); The text starts on the right side, but still gets append to the end as you type instead of being inserted at the beginning of the line. Update: I don’t know why it doesn’t work … Read more
This is a VERY basic example. This basically walks the document to find the position of the word within the document and ensures that the text is moved to the viewable area. It also highlights the match public class MoveToText { public static void main(String[] args) { new MoveToText(); } public MoveToText() { EventQueue.invokeLater(new Runnable() … Read more