Help Wanted

Java Swing – skynes

Skynes
Member

Posts: 202
From: Belfast, N Ireland
Registered: 01-18-2004
I'm doing a file handling project in java displaying a GUI in Java swing.

A couple of things I need to know (it's research) are:

Change background colour.
More control over layout of buttons and text boxes.
Adding pictures to the panes.
Adding pictures in the databse file.

This is going to be based on a CD Stock Control system if that helps any.

Any help available on the above is really appreciated.

GUMP

Member

Posts: 1335
From: Melbourne, FL USA
Registered: 11-09-2002
Change background color:

setBackground(new Color(r,g,b) );

RGB values range from 0-255.

Here's a class I wrote for displaying a loading screen image while the rest of the program is loading (I edited some personal stuff out):

package changedforedit;

import java.awt.*;
import javax.swing.*;

/** Displays a nice little logo.
* @author Gump!
*/
public class WelcomeDialog extends JDialog {
/** No description.
*/
private JPanel panel = new JPanel();
/** No description.
*/
private BorderLayout borderLayout = new BorderLayout();
/** No description.
*/
private ImageIcon imageIcon;
/** No description.
*/
private JLabel imageControl = new JLabel();
/** No description.
*/
private String imagefileS;

/** No description.
* @param frame Attached frame.
* @param title Title of the Frame.
* @param modal No description.
* @param image Name of the image being displayed.
*/
public WelcomeDialog(Frame frame, String title, boolean modal, String image) {
super(frame, title, modal);
imagefileS = image;
try {
jbInit();
pack();
}
catch(Exception ex) {
ex.printStackTrace();
}
}

/** No description.
*/
public WelcomeDialog() {
this(null, "", false, "");
}

/** No description.
* @throws Exception No description.
*/
void jbInit() throws Exception {
panel.setLayout(borderLayout);
getContentPane().add(panel);
panel.add(imageControl, BorderLayout.CENTER);
imageIcon = new ImageIcon(WelcomeDialog.class.getResource(imagefileS));
imageControl.setIcon(imageIcon);
}

/** Overloaded show method that loads up a counter thread.
*/
public void show() {
WelcomeTimer timer = new WelcomeTimer(this);
timer.start();
super.show();
}


/** This thread counts down and then closes and destroys the loading picture frame.
*/
class WelcomeTimer extends Thread {

/** No description.
*/
WelcomeDialog dialog;

/** No description.
* @param dialog Passes the pointer to the frame being watched by the thread.
*/
public WelcomeTimer(WelcomeDialog dialog) {
this.dialog = dialog;
this.currentThread().setPriority(Thread.MIN_PRIORITY);
}

/** No description.
*/
public void run() {
try {
sleep(15000);
} catch (Exception e) {}
dialog.dispose();
}
}
}

[This message has been edited by Gump (edited March 05, 2004).]

Skynes
Member

Posts: 202
From: Belfast, N Ireland
Registered: 01-18-2004
Thanx I'll try and see if I can firstly understand that (uses quite a bit of code I don't know) and secondly if I can use it myself. My team wanted a timer based Splash screen for this. Just for the extra marks of doing something on top of the basics
CobraA1

Member

Posts: 926
From: MN
Registered: 02-19-2001
quote:

More control over layout of buttons and text boxes.

Most of my programs use a combination of GridBag and Border layouts. Some IDEs also offer some sort of absolute positioning layout. I think you can do absolute positioning with the null layout also.

------------------
There are only 10 types of people - those who understand binary, and those who don't.
Switch Mayhem now available! Get it here
Codename: Roler - Writing object code and GUI.

GUMP

Member

Posts: 1335
From: Melbourne, FL USA
Registered: 11-09-2002
Yeah, most of my windows use absolute positioning. I prefer to control my window properties manually and not use the premade layouts.

Just use this function:

getContentPane().setLayout(null);

Then specify everything else.

Skynes
Member

Posts: 202
From: Belfast, N Ireland
Registered: 01-18-2004
by specify you mean something like (0,100,0,100)?