Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners How to solve button problem
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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



Advertisement
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
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
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..
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
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
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 the Hibernate Common Exceptions?
How to solve the Hibernate Common Exceptions?  How to solve the Hibernate Common Exceptions
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
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
Solve it
Solve it  How to calculate the value which contains oparator and operand both using command line argument
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
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
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 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
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 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
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
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 '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 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 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
Advertisements
 

 

 

DMCA.com