How to solve button problem

How to solve button problem

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 Tutorials/Questions & Answers:
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
Advertisements
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 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
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
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
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
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
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
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
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
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
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
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
How to solve the Hibernate Common Exceptions?
How to solve the Hibernate Common Exceptions?  How to solve the Hibernate Common Exceptions
how to solve this kind of error in Eclipse IDE?
how to solve this kind of error in Eclipse IDE?   i'm creating... are installed. but i'm getting exactly this error, any one out of this problem... button, to click and displaying this window
Solve it
Solve it  How to calculate the value which contains oparator and operand both using command line argument
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
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
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
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 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
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
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
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
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
how to use button in array
how to use button in array  plz tell me how to code for button in array
How to get Button Id ?
How to get Button Id ?  How to get Button ID instead of its value in Servlet. (I am not using jsp right now
how to solve 'Stop Running This Script' Error ?
how to solve 'Stop Running This Script' Error ?  Hi.. When opened the page on IE browser(version : 8.0),it gives an java script error (i.e.Stop Running This Script). I have used jsp/servlet for this. Please help to resolved
How to solve ModuleNotFoundError: No module named 'paramiko' error
How to solve ModuleNotFoundError: No module named 'paramiko' error  Hi, while importing following module: import paramiko I am getting the error... 'paramiko' How to solve ModuleNotFoundError: No module named 'paramiko' error
How to solve ModuleNotFoundError: No module named 'paramiko' error
How to solve ModuleNotFoundError: No module named 'paramiko' error  Hi, while importing following module: import paramiko I am getting the error... 'paramiko' How to solve ModuleNotFoundError: No module named 'paramiko' error
please help me solve this problem when i am create database connection using servlecontext
please help me solve this problem when i am create database connection using servlecontext  hi... I have create a database connection using... understand what is the problem .... the code are as follows. the servlet context
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
How can we solve this puzzle using java ?
How can we solve this puzzle using java ?  Sachin likes sweets a lot. So, he goes to a market of sweets. There is a row of sweet stalls. Every sweet... someone help how can we write the code
how to solve error like'java.lang.NumberFormatException: For input string: "7600113411"' this
how to solve error like'java.lang.NumberFormatException: For input string: "7600113411"' this  java.lang.NumberFormatException: For input string: "7600113411"    java.lang.NumberFormatException: For input string
How to make a button of different behaviour?
How to make a button of different behaviour?  Suppose In a jsp page I have a button SAVE with id="btnSave" value="SAVE" and a javascript function... of SAVE button will call ajaxInsertUpdateData(document.getElementByID("btnSave
How to display button as a link in vaadin?
How to display button as a link in vaadin?  Hello, I am working on a Vaadin based web application. I want the button to be displayed like link... a button. How to achieve this? Thanks   Hi, You can use the following code
Button
Button  How to use image for button in JSF
How to Create Button With TableView in iphone
How to Create Button With TableView in iphone  My requirement is i am creating one button. when i press the button TableView will display... on the button can u please send me the code i want to create converter app. thanks
how to disable browser back button
how to disable browser back button  Am doing a web application in that how to disable browser back button using java script
How to draw a web button, draw a web button, web button
How to draw a web button       Be ready to learn a simple technique to draw a web button, if you are not able to make a web button follow every steps that are give in this example
How to design a dollar button, design a dollar button, a dollar button
How to design a dollar button       Here, I am going to draw a dollar button by using this tutorial. New File: Take a new file as appropriate size.ADS_TO_REPLACE_1 Draw
How create an overlay button on different containing div
How create an overlay button on different containing div  How to create an overlay button on different containing div
How to call java method on Button click in jsp?
How to call java method on Button click in jsp?  How to call java method on Button click in jsp
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
Pass value of rasio button from jsp page to action class(not conventional problem)
Pass value of rasio button from jsp page to action class(not conventional problem)  Hi, I have a jsp page that has code which goes ike this: <... button) to be deleted On clicking 'delete' button . Hence I need to pass eventId

Ads