jbutton

jbutton

View Answers

November 24, 2009 at 1:13 PM

Hi Friend,

Try the following code:

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

public class JListExample extends JFrame{
static final String Select = "Sports";
String input = "";
DefaultListModel listModel;
JList list ;
public JListExample() {
super(Select);
JButton button=new JButton("Add");
listModel = new DefaultListModel();
list = new JList(listModel);
JScrollPane pane=new JScrollPane(list);
JPanel panel=new JPanel();

ActionListener lst = new ActionListener() {
public void actionPerformed(ActionEvent e) {
String[] sport = new String[] {"Cricket", "FootBall", "Tennis", "Hockey" };
input = (String) JOptionPane.showInputDialog(JListExample.this,"Please select your favorite sport",Select, JOptionPane.INFORMATION_MESSAGE, null, sport,"Tennis");

listModel.addElement(input);
}
};

button.addActionListener(lst);
panel.add(button);
panel.add(pane);

add(panel);
pack();
setVisible(true);

}
public static void main(String argv[]) {
new JListExample();

}

}

Thanks









Related Tutorials/Questions & Answers:
jbutton
jbutton  How to use enter function in jbutton?plzz help
Jbutton
Jbutton  How to get the enter key function in multiple jbutton
Advertisements
How to put an image on a JButton?
How to put an image on a JButton?  How to put an image on a JButton
Jbutton[] background & foregroundcolor change
Jbutton[] background & foregroundcolor change  how to change the color of the selected JButton in java swing. I am create JButton in an array JButton button[]=new JButton[100]; if i select button[5] then the Jbutton
how to reduce width of jbutton ?
how to reduce width of jbutton ?  how to reduce width of jbutton ? thanks in advancwe
3D JButton in java?
3D JButton in java?  how we can create 3D button in java. thanks
Jbutton in JTable cells
Jbutton in JTable cells  I am a Java Beginner... I want a code in which I display data in Jtable from database and correspondingly a JButton for each cell and when i click on that button a new window should open
jbutton - Java Beginners
jbutton  Hi, I have jlist and jbutton options.If i select... are displyed in the jlist using jbutton(refresh button). I want to know how to refresh... listModel; JList list ; public JListExample() { super(Select); JButton
How to put points on a JButton
How to put points on a JButton  I wanted to ask....what am i supposed to do if i wanna set points on my JButton so as to be able to draw arcs or curves.... supposedly my button represents a tile with 2 openings and the opening
Java Swing : JButton Example
Java Swing : JButton Example In this section we will discuss how to create button by using JButton in swing framework. JButton : JButton Class extends... JButton labeling with some String .Some events are handled with the button
Open TextFile on JButton Click - Java Beginners
Open TextFile on JButton Click  Hello Sir I Want to open TextFile on JButton Click. plz Help Me  Hi Friend, Do you want to simply open the text file or you want to open the file using JFileChooser,read that file
how to open a file with a jbutton? - Java Beginners
how to open a file with a jbutton?  Hello Is it possible that by clicking on a button it can open java html file or doc exists on the pc? I searched and I found that it is possible to open a web page so I tried to open
How to Open Text or Word File on JButton Click in Java - Java Beginners
How to Open Text or Word File on JButton Click in Java  How to Open Text or Word File on JButton Click in Java
Create and Show Wordpad File on JButton Click - Java Beginners
Create and Show Wordpad File on JButton Click  Hello Sir I want to create wordpad or word document on JButton Click Event.which contains data which...; import org.apache.poi.poifs.filesystem.*; class Form extends JFrame{ JButton
Open Text or Word Document on JButton Click in Java - Java Beginners
Open Text or Word Document on JButton Click in Java  How to open Word document or Text File on JButton Click in java  Hi Friend, Try... JFrame{ JButton ADD; JPanel panel,pan; JLabel label1,label2,label3,label4
Adding a Rollover and Pressed Icon to a JButton Component in Java
Adding a Rollover and Pressed Icon to a JButton Component in Java... about adding event i.e. the rollover and click icon to a JButton component of swing... of the JButton class which is used to set the icon or image to a button for display
Changing the Label of a JButton Component in Java
Changing the Label of a JButton Component in Java... to change the label of a button in java swing. JButton is the component of javax.swing....;);   button = new JButton("Click Me");  
Java JButton Key Binding Example
Java JButton Key Binding Example In this section we will discuss about how... on JButton. In this example I want to save the data of a JTextField added... and created another JPanel for adding the JButton and then added these panel
Sum of a Number using Swing
. JTextField, JButton is a component of GUI. Brief description of the Component...;JTextField text2 = new JTextField(20); 3. JButton...;JButton("Calculate"); ADS_TO_REPLACE_3 Step: Create a file "
Code how to? - Java Beginners
Code how to?  how to access a separate form using a JButton ? Also how to let another Jbutton access an excel spreadsheet for viewing? Thanks
java - Swing AWT
java    while inserting in data in text field and click the jButton and save the data in sql 2005
regarding JTable - JDBC
regarding JTable  how to populate a JTable with mysql data after clicking JButton please explain with the example
java swings - Java Beginners
java swings  Hi, I need simple code for JButton JOptionPane.Please send the code. Thanks, Valarmathi
ArrayList - Java Beginners
{ JTextField txtAdd=new JTextField(35); JButton btnAdd=new JButton("Add"); JButton btnSize=new JButton("Size"); JButton btnFirst=new JButton("First"); JButton btnLast=new JButton("Last"); JButton btnFind=new JButton("Find
images - Java Beginners
); content.setLayout(new FlowLayout()); JButton button1 = new JButton.../vinod/amarexamples/javalogo.gif"); JButton button2 = new JButton(cup); content.add(button2); JButton button3 = new JButton("Java", cup
scrollbar in JPanel
f = new Frame ("Demo");JPanel p = new JPanel();JButton b1 = new JButton("Button 1");JButton b2 = new JButton("Button 2"...) { Frame f = new Frame ("Demo"); JPanel p = new JPanel(); JButton b1 = new JButton
java compilation - Java Beginners
extends JPanel { ActionButtonsPanel () { JButton addBut = new JButton("Add"); JButton multBut = new JButton("mult"); add(addBut); add(multBut... { ActionButtonsPanel () { JButton addBut = new JButton("Add"); JButton
java compilation error - Java Beginners
); } } class ActionButtonsPanel extends JPanel { ActionButtonsPanel () { JButton addBut = new JButton("Add"); JButton multBut = new JButton("mult"); add(addBut); add...{ ActionButtonsPanel () { JButton addBut = new JButton("Add"); JButton multBut = new
Java enter Key problem - Java Beginners
Java enter Key problem  How we can use Enter Key to Click a Button(JButton) in Java?  hi, i guess u mean u want to make a button...().setDefaultButton(JButton defaultButton) thats
file reader
(label2); JButton b1 = new JButton("file1"); panel.add(b1); JButton b2 = new JButton("file2"); panel.add(b2); JButton b3 = new JButton...("bluepaw.gif"); JButton iconButton1 = new JButton(icon11
Java code - Java Beginners
Java code  how to make a program in java(Jbutton) if there is a combination numbers inorder to exit the program else the background color of the frame will turns red
source code - Swing AWT
source code  source code for a program to shutdown, restart, log off the pc after clicking jbutton on jpanel or a jframe by user. thanks in advance
Scroll in JPanel
JPanel(); JButton b1 = new JButton("Button 1"); JButton b2 = new JButton("Button 2
Adding JTable into existing Jframe.
"); JButton add=new JButton("ADD NEW"); JButton edit=new JButton("EDIT"); JButton delete=new JButton("DELETE"); JButton save=new JButton("SAVE"); JButton cancel=new JButton("CANCEL"); JButton close=new JButton("CLOSE"); JButton print
Adding JTable into existing Jframe.
"); JButton add=new JButton("ADD NEW"); JButton edit=new JButton("EDIT"); JButton delete=new JButton("DELETE"); JButton save=new JButton("SAVE"); JButton cancel=new JButton("CANCEL"); JButton close=new JButton("CLOSE"); JButton print
Adding JTable into existing Jframe.
"); JButton add=new JButton("ADD NEW"); JButton edit=new JButton("EDIT"); JButton delete=new JButton("DELETE"); JButton save=new JButton("SAVE"); JButton cancel=new JButton("CANCEL"); JButton close=new JButton("CLOSE"); JButton print
java
java  find the errors in the following code fragment and explain how to correct them button1=new JButton("OK"); JTextField text1=JTextField(10...); c.add(text1);   JButton button1=new JButton("OK"); JTextField text1
JTable - Cell selection - Swing AWT
); getContentPane().add(spane); JButton button = new JButton("Click Button...); table.requestFocus(); } }); final JButton jbutton = new JButton("De...()) { table.editingStopped(new ChangeEvent(jbutton
SplitButton of dropdownbutton invisible when mouse clicking - Swing AWT
javax.swing.plaf.basic.BasicArrowButton; public class SplitButton1 extends JButton { private JButton mainButton, dropDownButton; private JMenu dropDownMenu...(String text) { this(new JButton(text), SwingConstants.SOUTH
Java Calculator program - Java Beginners
; String s1,s2,s3,s4,s5; Frame f; JButton...; Calculator() { f=new Frame("Calculator"); p=new Panel(); b1=new JButton("0"); b1.addActionListener(this); b2=new JButton("1"); b2.addActionListener
Jtabbedpane - Java Beginners
with the user by this button. So...;Java Example for adding abstarct JButton...(tab, BorderLayout.CENTER); JButton   Java Example for adding abstarct JButton in JTabbedPane and interacting with user using this JButton.Code
java buttons - Swing AWT
= new JFrame("JFrame"); final JPanel p1 = new JPanel(); JButton a = new JButton("A"); JButton b = new JButton("B"); p1.add(a); p1.add(b...()); JButton c = new JButton("C"); p2.add(c); f.setSize(150, 100
How to close a frame on action event of a button from a different class ?
? I have a designed a control-frame on 1 class which has jbutton components, I... was opened when I had press first jbutton from control-frame) when I press second jbutton from control-frame
Non Editable Text File in java - Java Beginners
Non Editable Text File in java  Hello Sir ,I want to Show NonEditable TextFile on JButton Click which Contains User Manual of Project ,How I can Do It. plz Help Me
button with rounded corner in java
button with rounded corner in java  Hi, I want to create a JButton with rounded corners in swings. I went through many programs but did not got the solutions. Thanks and regards, Vivek BirdiADS_TO_REPLACE_1
JFrame
JFrame  write an application with a JFrame that five labels describing reasons that a customer might not buy your product(for example "Too expensive") every time the user clicks a Jbutton, remove one of the negative reasons
Java Swing Scientific Calculator
= 0, z = 0; char ch; JButton b1, b2, b3, b4, b5, b6, b7, b8, b9, zero, clr...)); boolean t = true; mr = new JButton("MR"); buttonpanel.add(mr); mr.addActionListener(this); mc = new JButton("MC"); buttonpanel.add(mc
program a combination locker
and limitations of 1 to 9 by 1 The Reset JButton will reset all the JSpinners to the default value of 5. The Open JButton will test to see if the combination set
Gui Interface - Java Beginners
Gui Interface  hi I have two seperate interfaces in the same projects . my question is how can I access this interface using a jbutton (i.e jbutton = next where next points to another interface addCourse.java) What would
GUI problem - Java Beginners
; Handle the actionPerformed event for JButton and try doing something like...; Handle the actionPerformed event for JButton and try doing something like

Ads