Home Answers Viewqa Java-Beginners How to solve button problem

 
 


talupularamesh
How to solve button problem
1 Answer(s)      4 years and 6 months ago
Posted in : Java Beginners

View Answers

November 14, 2008 at 12:31 AM


Hi friend,

Please implement following code.


import java.awt.*;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import javax.swing.JTabbedPane;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.StyledDocument;

public class ExampleGUI extends JFrame {
private static final long serialVersionUID = 1L;

private JTabbedPane tabbedPane;
private JTextPane messageArea;

private class NewTabListener implements ActionListener
{
public void actionPerformed(ActionEvent arg0)
{
StyledDocument doc = (StyledDocument)messageArea.getDocument();
try{
doc.insertString(doc.getLength(), "new line\n", null);
}
catch (BadLocationException e){
e.printStackTrace();
}
tabbedPane.add("tab", new JPanel());

}
}

private GridBagConstraints setGridBagConstraints(int gridx,
int gridy,
int gridwidth,
int gridheight,
double weightx,
double weighty,
int fill,
int anchor,
int insets1,
int insets2,
int insets3,
int insets4){

GridBagConstraints gridConstr = new GridBagConstraints();

gridConstr.gridx = gridx;
gridConstr.gridy = gridy;
gridConstr.gridwidth = gridwidth;
gridConstr.gridheight = gridheight;
gridConstr.weightx = weightx;
gridConstr.weighty = weighty;
gridConstr.fill = fill;
gridConstr.anchor = anchor;
/* Insets(int top, int left, int bottom, int right) */
gridConstr.insets = new Insets(insets1, insets2, insets3, insets4);

return gridConstr;
}

public ExampleGUI(){
this.setTitle("Example GUI");
this.setResizable(true);
this.setSize(600, 400);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

tabbedPane = new JTabbedPane();
messageArea = new JTextPane();

JPanel mainPanel = new JPanel();

mainPanel.setLayout(new GridBagLayout());
GridBagConstraints gridConstr;

gridConstr = setGridBagConstraints(0, 0, 1, 1, 1.0, 90.0, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0);
mainPanel.add(tabbedPane, gridConstr);

gridConstr = setGridBagConstraints(0, 1, 1, 1, 1.0, 10.0, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0);
mainPanel.add(messageArea, gridConstr);

JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem newTab = new JMenuItem("new tab");
menu.add(newTab);
menuBar.add(menu);
newTab.addActionListener(new NewTabListener());

JMenuItem newTab1 = new JMenuItem("Open");
menu.add(newTab1);
menuBar.add(menu);

JMenu menu1 = new JMenu("Edit");
JMenuItem newTab2 = new JMenuItem("Undo");
menu1.add(newTab2);
menuBar.add(menu1);

this.setJMenuBar(menuBar);
this.getContentPane().add(mainPanel);

}

public static void main(String[] args){
ExampleGUI exampleGUI = new ExampleGUI();
exampleGUI.setVisible(true);
}

}
-------------------------------------------

Visit for more information.

http://www.roseindia.net/java/example/java/swing/

Thanks.









Related Pages:
How to solve button problem - Java Beginners
How to solve button problem  I have created button (Open File Dialog... equal space So button size also increasing. Could you please guide me how to solve this problem. Thank you Sir, Yours truly, T.Ramesh Puttaparthy
how to solve an internet connection problem
how to solve an internet connection problem  when i run my..." java.lang.UnsupportedOperationException: Not yet implemented the problem is that i don`t know how to implement
Solve this problem plzzz
Solve this problem plzzz  Prashant.jsp (this is my JSP file) <... kindly help me and check all those files and solve my problem as soon as possible...;/tr> </table> <br><input type="button
how to solve this problem for oracle connectivity
how to solve this problem for oracle connectivity  Exception in thread "main" java.sql.SQLException: Io exception: The Network Adap ter could not establish the connection
how do i solve this problem?
how do i solve this problem?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access
Solve it
Solve it  How to calculate the value which contains oparator and operand both using command line argument
Please Help To Solve My Problem
Please Help To Solve My Problem  PHP I Have 6 Textbox and 1 ok button. 6 Textbox to Add the 6 Team Name. Each Team Name In String(Like- A,B,C,D,E,F) When I Add This Six Team Name In Six Text Box Then I Will Click On Ok Button
can interface solve this problem in java
this calander class. can interface solve this problem. If yes then how. pls...can interface solve this problem in java  I have a JDialog which displays the calendar [from 2010-2020], i created this in a different class
Simple problem to solve - JSP-Servlet
Simple problem to solve  Respected Sir/Madam, I am.... But in that I am facing a very very minute problem. The alert boxes are displayed... must display in the home page itself after clicking submit button. I am sending
Simple problem to solve - JSP-Servlet
Simple problem to solve  Respected Sir/Madam, I am.... But in that I am facing a very very minute problem. The alert boxes are displayed... must display in the home page itself after clicking submit button. I am sending
solve this problem
solve this problem  I typed this program and compiled.The program is compiled but when i eneterd url in tomcat server. Its not giving error but only... in table please tell me the solution for thid problem import java.io.*; import
Struts 2 radio button value problem
somebody tell me how to solve this problem? Thanks in advance...Struts 2 radio button value problem  When I use s:radio tag in struts 2, I'm not able to get the selected value using document.getElementById
Swing Problem on submission of button
Swing Problem on submission of button  How to close current frame (Frame1) and open a new frame (Frame2) already created and pass the data to frame2 from frame1 on the clicking of button in swing
Radio Button Problem in jsp.
Radio Button Problem in jsp.  I have a small doubt in my application, my requirement is to get a "single selectible row", I generated a radio button... deepak . i got the soution.   Hi deepak, how to get the multiple selected
how to solve
how to solve   log4j:WARN No appenders could be found for logger (org.apache.struts.util.PropertyMessageResources). log4j:WARN Please initialize the log4j system properly
plz solve my query?
plz solve my query?  how to remove all the options from select control in html using java script?   JavaScript remove all items <...;/select> <br> <input type="button" value="Remove All Item" onClick
how to solve this..
how to solve this..  Given a list of students and their marks Name | Science | Math | English | Computer Ahmad | 28 | 100 | 66 | 34 Samad | 56 | 89 | 55
how to solve this..
how to solve this..  Given a list of students and their marks Name | Science | Math | English | Computer Ahmad | 28 | 100 | 66 | 34 Samad | 56 | 89 | 55
help me to solve this problem..
help me to solve this problem..  Given below is a class definition for Book. Type and compile the class, and answer the following questions: class Book { String title; //bookâ??s title double price; //bookâ??s price
Small Bug How to solve in my code
Small Bug How to solve in my code  String season=""; pst...") + ","; it shows bug in findbugs tool.. but it executes successfully how to solve the problem
solve this pbm
solve this pbm  sir rows are also inserting i have checked in the database also the rows are not affected in the table . The first pbm wich i have sent to you is not yet solved.......... pls give me detail explaination how we
i need help to solve this problem
i need help to solve this problem  Write a stack class ArrayStack.java implements PureStack interface that reads in strings from standard input and prints them in reverse order. and Show step by step what queue will look like
jsp problem
to the viewer. how to do this please help me to solve... enterd data when click on preview button it as to seperate data for every 42 lines
Button
Button  How to use image for button in JSF
back button issue - Java Beginners
of problem there is two solutions 1- you can disable the back button of the browser. 2- through session management u can solve this problem.  Hi friend...back button issue  Hello, I have a site that asks for user
disable back button - Java Beginners
details with source code to solve the problem. Thanks  Hello...disable back button  I wanted the code for disabling back button... displayed but..when i click back button i go back to the register page which should
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can we retriving dat from database, capturing data, moving to next page.. etc
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can be retriving dat from database, capturing data, moving to next page.. etc
How to solve the Hibernate Common Exceptions?
How to solve the Hibernate Common Exceptions?  How to solve the Hibernate Common Exceptions
how to set size of button,textfield.
how to set size of button,textfield.  how we set size of button textfield etc and reduce problem when click maximize button the text or textfield get large how to set as a preferd size in the panel or frame .when we click
i dont no how to solve it pls
i dont no how to solve it pls   Calculate and display the sum of all prime number from 1 to 100 covert in java system codes
JSF Command button problem - Java Server Faces Questions
JSF Command button problem  Hi Frnds... I have retrieved the records from the mdb file in backing bean..if i click the submit button those... in the form of table when i click the button for the second or third time... why cant
Facing Problem with submit and cancel button in same page - Struts
Facing Problem with submit and cancel button in same page  Hi, can u please help me out.I have placed submit and cancel button in the jsp page but i am unable to know how to write the form and action classes   Hi
How to Solve the Syntax Error in java??
How to Solve the Syntax Error in java??  Syntax error in java? i have tried this program its showing error like this in Eclipse "Syntax error... of the program "objectname.i" What is the reason for this error??How to access the variable
how do i solve this question?
how do i solve this question?  1.Define a class named Circle with the following properties: a) An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier
how should i can solve
how should i can solve  Web based program - Input - Person's contact details with Passport Number as Unique Key. Save data in to oracle / MySQL. Output - List of Persons saved in the database. Technology to be used - JSP
Struts 2 Radio Button
result. Can you please help me further how to solve... radio buttons and I am using Struts2 tag.I want first rado button to be selected by default.But when i select the second radio button and hit on search
solve it - Java Beginners
solve it  Hi friend, I want to use switch case in jsp please let me know how to call page in jsp using include tag i want call this file using include tag please help me use switch statement in jsp
to solve the error - Java Beginners
to solve the error  class bubbleSort1{ public static void...++) { // count how many times // This next loop becomes shorter and shorter for (int i=0...; pass++) { // count how many times // This next loop becomes shorter
solve this
solve this   Create a student class. The student object should have studentid, studentname, subject and marks as properties. Also generate the getter and setter methods. Create 5 objects of this class and populate values
radio button - Development process
radio button  hello,i want to creat two radio button.out of which only one can be selected.and can show the contain of selected radio box   Hi friend, Code to solve the problem : My Page Radio 11
problem - WebSevices
problem  i am using windows vista home basic.I installed tomcat6 succesfully and used the service for some application.But after restarting the machine i got an error message "unable to open the service tomcat6".how can i solve
Using radio button in struts - Struts
Using radio button in struts  Hello to all , I have a big problem... , but the radio button has only just one value that i can pass.what can i do to solve... source code to solve the problem : For more information on radio in Struts
in php installation problem ?
in php installation problem ?   php installation in 7th step did not display y/n dialog box how to solve the problem
how to solve the nullPointer Exception in main - Java Beginners
how to solve the nullPointer Exception in main  New to Java ,pls help me how fix Null pointer Exception in main: two files , split .java another is actualState1.java , I want to get value of spaceWord[1] from split.java
GUI problem
GUI problem  How do I make a Jbutton which is shaped like a circle. This button needs to be clicked in order to change color.   import...) { JButton button = new CreateRoundButton("Click"); button.setBackground(Color.gray
Solve using only Javascript loops...
Solve using only Javascript loops...  Write a JavaScript code, 1) to find a number of unique letters in string. (Eg. if keyword is unique, Unique...;td><input type="button" onclick="display();" value="Submit"></td>
how to use button in array
how to use button in array  plz tell me how to code for button in array
how to display the values of one list in other upon clicking a button in struts2
how to display the values of one list in other upon clicking a button... in struts2.. I have a problem, I have to display the values of one list in other list upon clicking a button...Can any one provide me the sample code.. Hope

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.