Hi - I am trying to create a startup screen (from and old splashscreen) with a disclaimer that people need to accept before they continue. There is a graphic on the left and next to it there is text that later expands under the graphic. In the future I will add two buttons.
I use a Gridbaglayout with the graphic in a Jlabel and the text divided into two areas one next to the graphic and the other below. But the code does not seem to work.
First the graphic does not stay anchored to the corner and second only the label appears.
Would someone please look at the code and tell me what I am missing.
Thanks...Ronnie
import java.awt.*;
import javax.swing.*;
public class SplashScreen extends JWindow {
private int duration;
public SplashScreen(int d) {
duration = d;
}
// A simple little method to show a title screen in the center
// of the screen for the amount of time given in the constructor
public void showSplash() {
JPanel content = (JPanel)getContentPane();
// JButton btn, btn2;
JTextArea text, text2;
Container contentPane = getContentPane();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
contentPane.setLayout(gridbag);
content.setBackground(Color.white);
// Set the window's bounds, centering the window
int width = 700;
int height =500;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width-width)/2;
int y = (screen.height-height)/2;
setBounds(x,y,width,height);
JLabel pict = new JLabel(new ImageIcon ("d:\\javaherb\\webseal_100.gif"));
c.anchor = GridBagConstraints.NORTHEAST;
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 1;
gridbag.setConstraints(pict, c);
contentPane.add(pict);
text = new JTextArea("AGMOD was developed to assist me in making up my mind and conservation efforts. " +
" The program is provided on an as is basis, with no technical support. " +
"The Club specifically disclaims any warranty, either expressed or implied, " +
" including but not limited to the implied warranties of merchantablility and ", 8, 28 );
text.setEditable(false);
text.setLineWrap(true);
text.setWrapStyleWord(true);
text.setFont(new Font("Arial", Font.BOLD, 20));
c.gridwidth = 1;
// c.gridheight = 1;
c.gridx = 1;
c.gridy = 0;
c.insets = new Insets(0,25,0,0);
gridbag.setConstraints(text, c);
contentPane.add(text);
text2 = new JTextArea("fitness for a particular use. The entire risk as to quality and performance is "+
"with the user. In no event will the Club, its staff or the developer of this \n", 3, 30 );
text2.setLineWrap(true);
text2.setWrapStyleWord(true);
text2.setFont(new Font("Arial", Font.BOLD, 20));
c.gridx = 0;
c.gridy = 1;
gridbag.setConstraints(text2, c);
contentPane.add(text2);
JButton btn = new JButton("Quit");
c.anchor = GridBagConstraints.NORTHEAST;
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 1;
gridbag.setConstraints(btn, c);
contentPane.add(btn);
JButton btn2 = new JButton("Agree");
c.anchor = GridBagConstraints.NORTHEAST;
c.gridx = 1;
c.gridy = 2;
c.gridwidth = 1;
gridbag.setConstraints(btn2, c);
contentPane.add(btn2);
Color oraRed = new Color(156, 20, 20, 255);
content.setBorder(BorderFactory.createLineBorder(oraRed, 5));
setVisible(true);
}
public void showSplashAndExit() {
showSplash();
// System.exit(0);
}
public static void main(String[] args) {
// Throw a nice little title page up on the screen first
SplashScreen splash = new SplashScreen(30000);
// Normally, we'd call splash.showSplash() and get on with the program.
// But, since this is only a test...
splash.showSplashAndExit();
}
}
I use a Gridbaglayout with the graphic in a Jlabel and the text divided into two areas one next to the graphic and the other below. But the code does not seem to work.
First the graphic does not stay anchored to the corner and second only the label appears.
Would someone please look at the code and tell me what I am missing.
Thanks...Ronnie
import java.awt.*;
import javax.swing.*;
public class SplashScreen extends JWindow {
private int duration;
public SplashScreen(int d) {
duration = d;
}
// A simple little method to show a title screen in the center
// of the screen for the amount of time given in the constructor
public void showSplash() {
JPanel content = (JPanel)getContentPane();
// JButton btn, btn2;
JTextArea text, text2;
Container contentPane = getContentPane();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
contentPane.setLayout(gridbag);
content.setBackground(Color.white);
// Set the window's bounds, centering the window
int width = 700;
int height =500;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width-width)/2;
int y = (screen.height-height)/2;
setBounds(x,y,width,height);
JLabel pict = new JLabel(new ImageIcon ("d:\\javaherb\\webseal_100.gif"));
c.anchor = GridBagConstraints.NORTHEAST;
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 1;
gridbag.setConstraints(pict, c);
contentPane.add(pict);
text = new JTextArea("AGMOD was developed to assist me in making up my mind and conservation efforts. " +
" The program is provided on an as is basis, with no technical support. " +
"The Club specifically disclaims any warranty, either expressed or implied, " +
" including but not limited to the implied warranties of merchantablility and ", 8, 28 );
text.setEditable(false);
text.setLineWrap(true);
text.setWrapStyleWord(true);
text.setFont(new Font("Arial", Font.BOLD, 20));
c.gridwidth = 1;
// c.gridheight = 1;
c.gridx = 1;
c.gridy = 0;
c.insets = new Insets(0,25,0,0);
gridbag.setConstraints(text, c);
contentPane.add(text);
text2 = new JTextArea("fitness for a particular use. The entire risk as to quality and performance is "+
"with the user. In no event will the Club, its staff or the developer of this \n", 3, 30 );
text2.setLineWrap(true);
text2.setWrapStyleWord(true);
text2.setFont(new Font("Arial", Font.BOLD, 20));
c.gridx = 0;
c.gridy = 1;
gridbag.setConstraints(text2, c);
contentPane.add(text2);
JButton btn = new JButton("Quit");
c.anchor = GridBagConstraints.NORTHEAST;
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 1;
gridbag.setConstraints(btn, c);
contentPane.add(btn);
JButton btn2 = new JButton("Agree");
c.anchor = GridBagConstraints.NORTHEAST;
c.gridx = 1;
c.gridy = 2;
c.gridwidth = 1;
gridbag.setConstraints(btn2, c);
contentPane.add(btn2);
Color oraRed = new Color(156, 20, 20, 255);
content.setBorder(BorderFactory.createLineBorder(oraRed, 5));
setVisible(true);
}
public void showSplashAndExit() {
showSplash();
// System.exit(0);
}
public static void main(String[] args) {
// Throw a nice little title page up on the screen first
SplashScreen splash = new SplashScreen(30000);
// Normally, we'd call splash.showSplash() and get on with the program.
// But, since this is only a test...
splash.showSplashAndExit();
}
}