Hack Forums
[Java] Extremely easy question. :) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Extremely easy question. :) (/showthread.php?tid=3185435)



Extremely easy question. :) - Zonated - Jan 17, 2013

I will preface by saying I'm a complete noob in all programming...which will become apparent when I post my question.

How can I make this into one dialog box that reads like the following link:

https://gyazo.com/96c356f050909fbc477fa3222b17bd1f

My first thought was to use JOptionPane.showMessageDialog(null, ""); beside each row, but that just made multiple dialog boxes.

Code
import javax.swing.JOptionPane;

public class test {

public static void main(String[] args) {

    System.out.println("  J  A  V  V  A ");
    System.out.println("  J    A A  V   V  A A");
    System.out.println("J    J   AA  V V  AA");
    System.out.println(" J  J   A  A  V  A  A");
}
}

I just began on the second chapter of Introduction to Java Programming and this was one of the questions, but I took it a step further by putting it in a dialog box. :P

Would you have to put all of that "JAVA" into one set of quotation marks for it to work or is there another way?

Thanks in advance for helping me learn. :)


* - Psifour - Jan 17, 2013

" J A V V A \n J A A V V A A\nJ J AA V V AA\n J J A A V A A"

That is what you need to use. \n will create a new-line and as such can be used to put multiple lines of text into a method that supports only a single string. Keep in mind that I don't use Swing so cannot verify that JOptionPane will support multi-line display.


* - Zonated - Jan 17, 2013

(Jan 17, 2013 10:03 PM)Psifour Wrote:  " J A V V A \n J A A V V A A\nJ J AA V V AA\n J J A A V A A"

That is what you need to use. \n will create a new-line and as such can be used to put multiple lines of text into a method that supports only a single string. Keep in mind that I don't use Swing so cannot verify that JOptionPane will support multi-line display.

Ah-ha! You are the man, good sir. I didn't realize \n would make it go to the next line. It works, now I would just have to figure out the spacing, which I'm messing around with now. Thanks. :)


* - +TOAST - Jan 18, 2013

JOptionPane actually uses Arial or Times New Roman to display text instead of a console font, so the spacing will be pretty wacky. (No set width characters)


* - Zonated - Jan 18, 2013

Yeah, I found that out. Lol. I made it look decent, but it didn't line up extremely well.

What's another way of doing it?


* - +TOAST - Jan 18, 2013

I believe you can change the font of the JOptionPane window to a fixed width font

Edit: apparently you can use this code before your messageDialogs to change the font:

Code
javax.swing.UIMAnager.put("OptionPane.font", yourFont);



* - Zonated - Jan 18, 2013

(Jan 18, 2013 10:54 AM)tasty_mother Wrote:  I believe you can change the font of the JOptionPane window to a fixed width font

Edit: apparently you can use this code before your messageDialogs to change the font:

Code
javax.swing.UIMAnager.put("OptionPane.font", yourFont);

Thanks for the info. I will try this out now. :)