Text « Graphics « Java Swing Q&A





1. Swing component prints text differently than it displays it    stackoverflow.com

I am printing a Swing component that contains text. The Swing component renders the text just fine on the screen, but, when I print it (to a .tif file), the ...

2. Java SWT - Text on Transparent Shell?    stackoverflow.com

In Java SWT, is there a way to draw text on a transparent shell so that only the text appears visible? What I would like to do is have the text ...

3. Drawing text in .NET with native look & feel    stackoverflow.com

I'm using .NET1 and I want to draw text as native. Is it possible by configuring graphics? I need to render the text as the System.Windows.Forms.Label does when the FlatStyle is set ...

4. In Java, it's possible change execution from Graphic Mode to Text Mode in Runtime?    stackoverflow.com

I making a webcrawler and I only need the GUI to set parameters for the crawling, after that, the execution runs forever in an infinite loop. It's possible when I start crawling ...

5. I want HIghlighted text to look bold    stackoverflow.com

When I select a piece of text in a JTextArea, it gets coloured in white and highlighted in blue (I'm using Nimbus LookAndFeel). I changed it so the highlight is white, and ...

6. Graphics#drawText, old text does not get erased    stackoverflow.com

I have a JPanel which overrides paintComponent like this

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);    
    //[...]
    g.drawString(" x ...

7. What is a Java library for outputting text formatted for printing?    stackoverflow.com

I'm working on a legacy Java program. I need to print out data reports in pure ASCII. Some of the data is in the form of tables which is tricky because ...

8. Easy multicolored text in Java    stackoverflow.com

After writing a console application (For mundane I/O tasks not worth mentioning here), I decided I needed to make the text multicolored for readability. I would've liked to keep it in ...

9. BasicTabbedPaneUI paint html text    stackoverflow.com

i would extend the BasicTabbedPaneUi so i can design my own tabPane. I have one problem with the html text, is to set the color of the text once the ...





10. How do we do text measurements without a prior call to paintComponent?    stackoverflow.com

Hi all I need to do some text measuring using java.awt.font.FontRenderContext, however this class requires me to supply a graphics object. From what I know, the only way I could ...

11. printing text    coderanch.com

12. Why won't this auto text-highlight work?    coderanch.com

Hello! Maybe someone can help me out with this one. I have a GTextArea (extends JTextArea) that some text is typed into. I have created a search/replace method that searches the text and puts results into a JTable. When a user double clicks on a result in the table, the text in the GTextArea (corresponding to the "find" in the table) ...

13. Changing the color of Selected Text    coderanch.com

14. Text in java.awt.Rectangle    coderanch.com

Okay, here's the extended Rectangle - import java.awt.*; public class StringRectangle extends Rectangle { protected String label; public StringRectangle( String s, int x, int y, int w, int h ) { super( x, y, w, h ); label = s; } public void setLabel( String s ) { label = s; } public String getLabel() { return label; } public void ...

16. Buggy text highlighting.    coderanch.com

//*************************************************************************** //* doOpenFromThis //*************************************************************************** private void doOpenFromThis(int row) { //A Vector containing information about a selection ResultRow resultRow = searchModel.getRow(row); JPanel toDisplay = (JPanel) resultRow.elementAt(4); row_mngr.dataPanel.scrollRectToVisible(toDisplay.getBounds()); //GTextArea extends JTextArea GTextArea textArea = (GTextArea) resultRow.elementAt(5); Integer selStart = (Integer) resultRow.elementAt(6); Integer selEnd = (Integer) resultRow.elementAt(7); //This works textArea.setSelectionColor(Color.blue); //This doesn't textArea.setSelectionStart(selStart.intValue()); textArea.setSelectionEnd(selEnd.intValue()); selectedArea = textArea; } //end doOpenFromThis





17. Print plain text with Printable interface    coderanch.com

Hi, Im trying to implement an printing component to use with an simple Java application, and im having problems with the fonts. The kind of printing is text plain, thus i must use an font that has fixed dimensions ( all characters with the same width and height ) to make the line breaking easer. Ive just use the Courier text ...

18. Rendering of text on canvas in jdk1.4    coderanch.com

19. Change text orientation on canvas    coderanch.com

20. How to turn the text vertical in graphics?    coderanch.com

Here's the method I use in JFreeChart to draw vertical labels for axes: /** * A utility method for drawing rotated text. *

* A common rotation is -Math.PI/2 which draws text 'vertically' (with the top of the * characters on the left). * * @param text the text. * @param g2 the graphics device. * @param textX the x-coordinate ...

21. How can I set the tabel headers text to a certain color?    coderanch.com

int j=1; String[][] data = new String[j][2]; for (int k=0; k

22. problem witch colors in java Text components    coderanch.com

import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; public class ColoredTextTest { public static void main(String[] args) { JTextPane textPane = new JTextPane(); textPane.setDocument(new DefaultStyledDocument()); textPane.setPreferredSize(new Dimension(1000, 500)); JPanel panel = new JPanel(); panel.add(textPane); JFrame f = new JFrame(); f.setJMenuBar(getMenuBar()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(panel)); f.setSize(400,300); f.setLocation(200,200); f.setVisible(true); } private static JMenuBar getMenuBar() { JMenu edit = new JMenu("edit"); edit.add(cut); edit.add(copy); edit.add(paste); JMenu ...

23. Colored text output????    coderanch.com

Following are the codes i've used to output my sequence in the main() method. It does give me the sequence that i want, but since i'm not femiliar with Swing stuffs, can anyone help with how to get the sequence(String) in colored text. Your help would be greatly appreciated. //a part of my code in the main() method. for(int x=0; x

24. Problem with drawing styled (attributed) text    coderanch.com

This works okay. import java.awt.*; import java.awt.font.*; import java.text.AttributedString; import javax.swing.*; public class AttributeTest extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); FontRenderContext frc = g2.getFontRenderContext(); AttributedString astr = new AttributedString("t1,2[s]"); astr.addAttribute(TextAttribute.BACKGROUND, new Color(0,255,0), 1, 4); astr.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB, 1, 4); astr.addAttribute(TextAttribute.SIZE, 36f); TextLayout textLayout = new TextLayout(astr.getIterator(), frc); textLayout.draw(g2, 150, 150); } public static ...

25. How can I send text characters to a printer device ?    coderanch.com

If that code doesn't work or you want to do anything more advanced than printing text, you'll have to use the Java Print Service[/QB] Hi Joe, unfortunately the code you posted does not print anything. As for Java Print Service, I tried that but you cannot print a text file with that, you can print the "image" of a text file: ...

26. Text surrounded by a rectangle    coderanch.com

import java.awt.*; import java.awt.font.*; import javax.swing.*; public class InnerText extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); int x = w/3; int y = h/4; int rectW = w*3/8; int rectH = h/4; g.setColor(Color.red); g.drawRect(x, y, rectW, rectH); Font font = g2.getFont().deriveFont(16f); g2.setFont(font); String text = ...

27. Quick way of drawing LED style text?    coderanch.com

borrowed from 74philip at sun's forums import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.text.SimpleDateFormat; import java.util.*; import javax.swing.*; class Stopwatch extends JPanel { JButton startButton, stopButton, resetButton; static JPanel buttonPanel; final int TOP = 1, // zero TOP,UPL,UPR,LOL,LOR,LOW 119 UPL = 2, // one UPR,LOR 36 UPR = 4, // two TOP,UPR,MID,LOL,LOW 93 MID = 8, // three TOP,UPR,MID,LOR,LOW 109 LOL ...

28. change the text color momentarily    coderanch.com

29. change the text color momentarily    coderanch.com

30. Marquee or Ticker (Moving Text in Horizontal)    coderanch.com

Hi, I am working in Stocks Application. As per my requirements, I need to add a marquee. That Marquee should take the values at runtime. That is text should be displayed in the marquee will keep on changing.i.e Share rate will keep on changing. I need to update in the displaying marquee. My inputs are String Array(String[]). I need to get ...

31. Each Item With Different text Color in a combox    coderanch.com

HI.. i am Using combobox for the selecting font color Selection... i want to display each Color in combobox with same the font color as its name... like Pink Text should be in Pink Color and Red Should be displayed with RED with Red Text Color in the Combobox... Any Idea or Clue...... Surely awaiting some good solution.. --Jamshaid..

32. Highlighting Text    coderanch.com

33. Print Text    coderanch.com

I am trying to print the text in a JTextArea, which is in a JScrollPane. Right now i am only able to print what is viewable in the JScrollPane. I would like to print all of the text in the JTextArea. Below is the code i have been using. Thanks!! public class SimulationResults extends JFrame implements ActionListener, Printable { ResultText newContentPane; ...

34. Preventing inserted text from becoming colored from previous style    coderanch.com

I have a jtextpane I have alreadly colored in black, and red. Red is for the text inside the brackets. This seems to work, but the problem is when I insert text imediately next to a red bracket, the next text that comes out is red as well, while it should be black. Right now what I'm doing to fix the ...

35. Coloring Text    coderanch.com

36. How to draw a line with text on it??    coderanch.com

37. Highlighting text    coderanch.com

38. setting different text colours    coderanch.com

39. color Java text    coderanch.com

hi, I have to show text as java text. I mean, to open file in an editor pane and to color the special words (like, highlight the key words (import, private, etc.) with the same color...) as a result I want to show the file as it is ahown in other editors of java(eclipse, netBeans, etc..) Does anybody know code that ...

40. Text highlighting    coderanch.com

Furthermore, use a DocumentFilter to intercept changes to the Document so you can find word boundaries. For instance, when you add text at location x, you need to check backwards from x for the last word boundary, check for the next word boundary after the inserted text, and parse the text in between. For instance, when the current text is "public ...

41. Printing in "html/text" format    coderanch.com

Hello, I'm working on a project and I want to print off a customer order. I want to be able to easily add sub headings wherever I want. It's also best to state here that I am quite new to Java. //Generate text to be printed public String generateOrderString() { StringBuilder deliveries = new StringBuilder(); StringBuilder requests = new StringBuilder(); StringBuilder ...

43. Drawing text along a line    coderanch.com

Hi, I am trying to implement drawing text along lines, or rather cubic curves. I found this page very useful ("Text along a path" section). However, this code draws text at the beginning of the line. What I need is to draw text at the end of the line. I tried modifying the code given on the website (TextStroke.java) and I ...

44. How do I draw "Best-Fit" text inside of a rectangle?    coderanch.com

I simply want to draw text inside of a rectangle. Easy. Harder: I would like the text to be as readable (translate: big) as possible with the constraint that it must be contained in the rectangle. I know about getAscent() and getDescent() and how to iterate through font types and sizes to find something that fits. But is there a more ...

45. Drawing text inside rectangles    coderanch.com

I have this task. I need to create rectangles and lines aand to put text inside the rectangle(comment box). I managed to cread rectangles and lines i can put text inside but the text is not displaying when i chancge the button(e.g i want to draw another rectangle after i created a comment box). I worked with JTextArea and seem to ...

46. change text color of highlighter    coderanch.com

hi. anybody knows which class or which particular method needs to be overridden in order to change the text color of the highlighter in a jtextpane? im doing this because if the highlighter's background color is black, the text color has to be white. currently it defaults to a gray color. the HighlightPainter does not have any means to do this, ...

47. Text in different colours    coderanch.com

The following brings up a text pane with some multi-coloured text - is this the right way to go about it? Any steps I can cut out / do more easily? import javax.swing.JFrame; import javax.swing.text.StyledDocument; import javax.swing.text.StyleConstants; import javax.swing.text.MutableAttributeSet; import java.awt.Color; import java.awt.BorderLayout; import java.awt.Font; import javax.swing.JTextPane; public class FontColourTest { public FontColourTest() { JFrame f = new JFrame(); JTextPane tp ...

48. Simple text printing with pagebreaks    coderanch.com

Hi, I have a report displayed in a GUI application as a simple text within JTextComponent. My goal is to print it but with page breaks at certain points. I have inserted \f at those places, however when I print page breaks are ignored and I get a weird character printed in those places where \f was and the rest of ...

49. Text color in disabled componentes    java-forums.org

The link got me to thinking... ^_^ Well, being completely honest, the GUI I built uses textfields, textareas and comboboxes to interact with the user. But I want the user to interact only when pressing certain buttons; the behavior I'm looking for is controlled by the "enable" property of the components. The problem is that while in "disabled" state, the text ...

50. text printing service in java    java-forums.org

51. Preventing inserted text from becoming colored from previous style    java-forums.org

I have a jtextpane I have alreadly colored in black, and red. Red is for the text inside the brackets. This seems to work, but the problem is when I insert text imediately next to a red bracket, the next text that comes out is red as well, while it should be black. Right now what I'm doing to fix the ...

52. highlight text    java-forums.org

Duplicate post closed. OP, please post only one thread per question. Also, you may wish to clarify your question greatly. I think that the reason it has not received any replies yet is that it is overly general and vague, and you've shown none of your code attempts, error messages, or provided any context. In fact, you'll want to read the ...

53. Simple text printing with pagebreaks    java-forums.org

Hi, I have a report displayed in a GUI application as a simple text within JTextComponent. My goal is to print it but with page breaks at certain points. I have inserted \f at those places, however when I print page breaks are ignored and I get a weird character printed in those places where \f was and the rest of ...

54. Printing text identically to AbiWord    java-forums.org

I am coding a medical program that needs to print identically to Abiword. The reason is because the user lays a 96 well plate onto a piece of paper to identify positives and the gui is text based. It took an act of God to get the black squares under the 96 wells to line up the first time in AbiWord. ...

55. Hi please help me with my program - highlight specific text    java-forums.org

Hi i want to create a program in Java, I want it to highlight specific text from a long story paragraph.. I want to use swing, I want to put the story paragraph to a JTextArea or JEditorPane, can I know how can I achieve to highlight specific text in from it?

56. Show different text colors on a GUI control    forums.oracle.com

Please don't answer this. The first time the OP posted a question it was it 2 forums. The next question was in 3 forums And finally this question is in 5 forums. The OP has been asked to stick to a single forum but apparently is ignoring everybody on the forum. Not only that the OP is posting in the AWT ...

57. Show different text colors on a GUI control    forums.oracle.com

Please don't answer this. The first time the OP posted a question it was it 2 forums. The next question was in 3 forums And finally this question is in 5 forums. The OP has been asked to stick to a single forum but apparently is ignoring everybody on the forum. Not only that the OP is posting in the AWT ...