Welcome Guest ( Log In | Register)



2 Pages V   1 2 >  
Reply to this topicStart new topic
> How To Create Java Button Or Frame, to be customized
negativezero
post Jul 29 2005, 11:11 AM
Post #1


Newbie [Level 1]
*

Group: Members
Posts: 24
Joined: 15-July 05
Member No.: 9,445



hi to all!!!!
just like to ask if it would be possible if i could make a custom button or frame in java.
i got tired of using the build infeatures in java.
i would like to create my own dessign of button or frame..
can it be possible!!! biggrin.gif

thank!!!! laugh.gif

Notice from BuffaloHELP:
New Help In! is NOT a descriptive topic title. Next time you decide not to follow the posting rules, you will be issued a week long ban.


This post has been edited by BuffaloHELP: Jul 29 2005, 03:49 PM
Go to the top of the page
 
+Quote Post
bjrn
post Aug 1 2005, 05:12 PM
Post #2


Super Member
*********

Group: Members
Posts: 378
Joined: 8-January 05
Member No.: 3,174



QUOTE(negativezero @ Jul 29 2005, 12:11 PM)
hi to all!!!!
just like to ask if it would be possible if i could make a custom button or frame in java.
i got tired of using the build infeatures in java.
i would like to create my own dessign of button or frame..
can it be possible!!! biggrin.gif

I'm not really sure what it is you want.

Java has a "look and feel" (LAF) as they call it, which can be switched. Normal Swing apps default to a certain look and feel which usually isn't too good looking. However you can change the look and feel used.

If you do mean the "look and feel", then the answer is that you can pick your own look and feel and plug it into your java app. You will have to bundle the LAF jar with whatever you are making obviously, because otherwise people will just get the "standard" look and feel.

Just google around for 'java "look and feel"' and you should be able to find plenty. Thow in the word "tutorial" and you'll no doubt find out exactly how to make your app use the look and feel you want it to.



But I'm not sure that is what you meant, if you meant something else, just say so smile.gif
Go to the top of the page
 
+Quote Post
wild20
post Aug 1 2005, 05:30 PM
Post #3


Never alone with Christ
*********

Group: Members
Posts: 647
Joined: 22-July 05
Member No.: 9,713



You can use a code that links to a picture or button link. But the image has to be uploaded onto you database. Just depends on what you want to do. I use html to make buttons and upload the pics to my database. That is the best way to do it in my ipinion. Just use a webmaster database and search for the answer. That is what I do. Sorry I couldn't be of more help. Have you tried a tutorial? You can always use those. Just use a search engine. That should give you the best answer. A tutorial that is.
Go to the top of the page
 
+Quote Post
beeseven
post Aug 3 2005, 12:36 AM
Post #4


Privileged Member
*********

Group: Members
Posts: 629
Joined: 26-February 05
Member No.: 3,995



You're being kind of vague, so I'm not exactly sure what you mean, but here are some neat things you can do with a JButton:

Let's assume we have a JButton called myButton.

This changes the font:
CODE
String name = "Serif"; //"Serif", "SansSerif", "Monospaced", or a font name
int style = Font.ITALIC //Font.ITALIC, Font.BOLD, or Font.BOLD | Font.ITALIC
int size = 14 //any number size
myButton.setFont(new Font(name, style, size));

Change colors:
CODE
myButton.setForeground(new Color(255,0,0)); //changes font color (in this case makes it red)
myButton.setBackground(new Color(0,0,255)); //changes background color (in this case blue)

Disable, reenable:
CODE
myButton.setEnabled(false);
myButton.setEnabled(true);

Add an image to display if it's enabled, or disabled:
CODE
ImageIcon ico = new ImageIcon("picture.gif"); //any image
myButton.setIcon(ico);
ImageIcon ico2 = new ImageIcon("otherpicture.gif");
myButton.setDisabledIcon(ico2);

Make the button plain text (but still a button):
CODE
button.setBorderPainted(false);
DDT TJ 08: button.setFocusPainted(false);
Go to the top of the page
 
+Quote Post
leiaah
post Oct 12 2005, 12:32 PM
Post #5


Super Member
*********

Group: Members
Posts: 436
Joined: 21-January 05
From: Koronadal City, Philippines
Member No.: 3,358



I'm not quite sure what you mean but I've dug up a few java projects in the past and I saw this code. To change the over-all look-and feel of your buttons (including the whole frame) just call these functions like this:
CODE
WindowUtilities.setJavaLookAndFeel();



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

public class WindowUtilities {

 //WINDOWS (or whatever your OS is) LOOK -->  WINDOWS BUTTONS

 public static void setNativeLookAndFeel() {
   try {
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
   } catch(Exception e) {
     System.out.println("Error setting native LAF: " + e);
   }
 }

 //JAVA LOOK -->  JAVA BUTTONS

 public static void setJavaLookAndFeel() {
   try {
     UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
   } catch(Exception e) {
     System.out.println("Error setting Java LAF: " + e);
   }
 }

  //DARK RED COLOR-->  COOLER-LOOKING BUTTONS!

 public static void setMotifLookAndFeel() {
   try {
     UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
   } catch(Exception e) {
     System.out.println("Error setting Motif LAF: " + e);
   }
 }

}


Now if you only need to change the buttons You can try to include an image in your button. By doing this:
CODE
buttonName.setIcon(new ImageIcon("images/btn1.gif"));
Go to the top of the page
 
+Quote Post
JField
post Jul 20 2006, 02:44 PM
Post #6


Member [Level 2]
*****

Group: Members
Posts: 77
Joined: 20-July 06
Member No.: 26,936



u can extend from JButton and set your wishes in constructer than whenever u want your button u can create it

class MyButton extends JButton{
public MyButton(){
write your wishes here

}

}

//then create it anywhere

new MyButton();
Go to the top of the page
 
+Quote Post
spieleforum
post Sep 3 2006, 03:32 PM
Post #7


Newbie [Level 2]
**

Group: Members
Posts: 26
Joined: 1-September 06
Member No.: 29,296



QUOTE(JField @ Jul 20 2006, 02:44 PM) *

u can extend from JButton and set your wishes in constructer than whenever u want your button u can create it

class MyButton extends JButton{
public MyButton(){
write your wishes here

}

}

//then create it anywhere

new MyButton();

Yes i would Prefer this way because its much easier than doing a own Look and Feel but when you create a own look and Feel you can change the Design of all Buttons in you Programm even the Buttons that are used in the programm bevore you created the new Look and Feel

i have a question too
he wanted to set up a background image to his new Button how can i do this? when i extend From "JButton" ?
Go to the top of the page
 
+Quote Post
salamangkero
post Sep 3 2006, 04:41 PM
Post #8


Super Member
*********

Group: [HOSTED]
Posts: 459
Joined: 15-August 06
From: Philippines
Member No.: 28,387



QUOTE(spieleforum @ Sep 3 2006, 11:32 PM) *
i have a question too
he wanted to set up a background image to his new Button how can i do this? when i extend From "JButton" ?


Ahh, subclassing, one of my favorite custom component strategy. To use background images, you probably have to mess with the void paint(Graphics g) method. Just draw the image before drawing everything else. happy.gif
Go to the top of the page
 
+Quote Post
Oleyum
post Nov 23 2006, 10:13 AM
Post #9


Newbie [Level 1]
*

Group: Members
Posts: 15
Joined: 14-February 06
Member No.: 18,640



QUOTE(wild20 @ Aug 1 2005, 06:30 PM) *