Jump to content

Print Format with GUI and change title of MessageDialog, HOW TO?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
thieflock

thieflock

    Newbie

  • Members
  • PipPip
  • 29 posts
Okay this is a two parter, first how do I right justify a JLabel. I would assume it goes in with the following code, this is after I declared all the GUI variables:

    // construct the components

	lName = new JLabel("Name");

	tName = new JTextField(15);

	bAccept = new JButton("Press Me");

And also how to I change the title of a message dialog box with JOptionPane.

Thanks agian, this site is alway a help.

#2
thieflock

thieflock

    Newbie

  • Members
  • PipPip
  • 29 posts
I figured it out myself and my findings were incase anyone else has this problem is:

To format a GUI label:

lName = new JLabel("Name", SwingConstants.RIGHT or LEFT);

And to changes the title of a MessageDialog box:

JOptionPane.showMessageDialog(null, "Hello", "Greetings");
Where Greetings in the title.

#3
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Thanks for posting your findings, people rarely do that

#4
gszauer

gszauer

    Programmer

  • Members
  • PipPipPipPip
  • 113 posts
The Correct Syntax for JOptionPane.showMessageDialog:
[HIGHLIGHT="Java5"]JOptionPane.showMessageDialog(parentComponent, messageStringExpression, boxTitleString, messageType)[/HIGHLIGHT]

parentComponent - Object that represents the parent of the dialog box. if there is no parent component, this is left as nul

messageStringExpression - The evaluated title that is displayed in the dialog box

boxTitleString - represents the title of the box

messageType - an int value representing the value that will appear in the dialog box
The following options are valid for messageType:
JOptionPane.ERROR_MESSAGE
JOptionPane.INFORMATION_MESAGE
JOptionPane.PLAIN_MESSAGE
JOptionPane.QUESTION_MESSAGE
JOptionPane.WARNING_MESSAGE

The correct Syntax for a simple dialog box:
[HIGHLIGHT="Java5"]JOptionPane.showMessageDialog(null, "Hello World", "Greetings", JOptionPane.PLAIN_MESSAGE)[/HIGHLIGHT]

~Aristotle said:

It is the mark of an educated mind to entertain a tought without accepting it
If my post was helpful, please help me build some rep Posted Image