Results 1 to 3 of 3
- 01-17-2013, 11:39 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 32
- Rep Power
- 0
As changes Are done on the JtextArea show graphics,How ?
Hello Everyone and thx in advance.
So my problem is I want to draw on a JPanel something on condition on what's been inserted in the JtextArea is this correct? :
DocumentListener to check on the insert operation
Methode to check the condition and draw on the JPanel :Java Code:protected class MyDocumentListener extends JPanel implements javax.swing.event.DocumentListener { @Override public void changedUpdate(javax.swing.event.DocumentEvent e) { // text has been altered in the textarea } @Override public void insertUpdate(javax.swing.event.DocumentEvent e) { // text has been added to the textarea try { //if not prompt Line if (!Traffic.getText(Traffic.getLineStartOffset(Traffic.getLineCount()-1), Traffic.getLineEndOffset(Traffic.getLineCount()-1)-Traffic.getLineStartOffset(Traffic.getLineCount()-1)).contains(">>")) {//if a line after a replace has been inserted if (Traffic.getLineCount() == (lastreplace + 2) ) { System.err.println(Traffic.getText(Traffic.getLineStartOffset(lastreplace), Traffic.getLineEndOffset(lastreplace) - Traffic.getLineStartOffset(lastreplace))); PortArchitecture (Traffic.getText(Traffic.getLineStartOffset(lastreplace), Traffic.getLineEndOffset(lastreplace) - Traffic.getLineStartOffset(lastreplace))); lastreplace +=1; } else//last line when it's not detected by the previous condition it'll be consumed here { System.err.println(Traffic.getText(Traffic.getLineStartOffset(lastreplace), Traffic.getLineEndOffset(lastreplace) - Traffic.getLineStartOffset(lastreplace))); PortArchitecture (Traffic.getText(Traffic.getLineStartOffset(lastreplace), Traffic.getLineEndOffset(lastreplace) - Traffic.getLineStartOffset(lastreplace))); } } Traffic.setCaretPosition(Traffic.getDocument().getLength()); } catch (BadLocationException ex) { Logger.getLogger(TrafficSerialPort.class.getName()).log(Level.SEVERE, null, ex); } } @Override public void removeUpdate(javax.swing.event.DocumentEvent e) { // text has been removed from the textarea } }
And another thing : I have some result concerning Showing some drawings but when I minimize the application all the graphics are gone.I know I need to call the repaint() but I don't know when and how.Java Code:public void PortArchitecture (String line) throws BadLocationException { Graphics2D gfx = (Graphics2D)graphicPanel.getGraphics(); String [] valuesId = new String [2]; valuesId = line.split(":"); /**switch (valuesId[0]) { case "Port Number" : draw(); }*/ if(valuesId[0].contains("Port number")) { gfx.drawString("(PN)", 30, 10); gfx.drawString(valuesId[1],30, 140); } if(valuesId[0].contains("Port Extension")) { gfx.drawString("(EXT)", 100, 10); gfx.drawString(valuesId[1], 100, 140); // draw(g); } if(valuesId[0].contains("Forward Extension")) { gfx.drawLine(140,80,140,110); // draw(g); } if(valuesId[0].contains("ON-HOOK")) { // draw(g); } if(valuesId[0].contains("OFF-HOOK")) { // draw(g); } if(valuesId[0].contains("Forward status")) { if(valuesId[1].contains("FORWARDED")) { // draw(g); } else { // draw(g); } } if(valuesId[0].contains("Dialing")) { //get dialed number //draw(g); } }
Help please!
- 01-17-2013, 05:35 PM #2
Re: As changes Are done on the JtextArea show graphics,How ?
Never use getGraphics() of a Component. Learn the correct approach to Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 01-21-2013, 12:27 PM #3
Member
- Join Date
- Dec 2012
- Posts
- 32
- Rep Power
- 0
Re: As changes Are done on the JtextArea show graphics,How ?


really it's making me crazy!!
now I want on the event of INSERT then draw how do I do that ?!!! please help
I tried to add the paintComponent(Graphics g) methods & I did override it and still dosn't work.
I undrestand that I need to call the class containing the paintComponent like this : frame.add(new MyPanel());
well I can't do that cause I need to get the event from the DocumentListener and I can't get it outside that Class, but still the paintComponent dosn't (I think) where to draw that's why nothing shows !!Last edited by taptaptill; 01-21-2013 at 01:19 PM.
Similar Threads
-
Graphics issue, pic won't show up.
By AndroidAppNewbie in forum New To JavaReplies: 1Last Post: 03-02-2011, 08:44 PM -
Graphics wont show up(paintComponent)
By TheBreadCat in forum New To JavaReplies: 3Last Post: 02-13-2011, 06:00 PM -
Why won't the scrollbar show up in a JTextArea?
By tjw09003 in forum New To JavaReplies: 2Last Post: 08-25-2010, 10:50 PM -
How can I show my log class in jTextArea
By mtz1406 in forum AWT / SwingReplies: 4Last Post: 10-29-2009, 12:15 PM -
How to always show the last line in my JTextArea?
By Ashley in forum New To JavaReplies: 1Last Post: 05-26-2007, 01:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks