I want code on placing textbox and Jbutton in a cell of JTable.Please
Dear All,
Iam doing project on swing and XMl iam using swing for fron end design. Here i have to use table in one cell i have to put textbox and button. please can any body send me the code. Pleae iam waiting for your valuable code.
regards,
surya
Hi I also want the same thing,
My requirement is like this, The content of the table will be kept on changing using a thread connecting to the servlet. SO the record number will be different
Can any one help me in this matter
Similar Messages
-
I want code on placing textbix and Jbutton in a cell of JTable.Please
Dear All,
Iam doing project on swing and XMl iam using swing for fron end design. Here i have to use table in one cell i have to put textbox and button. please can any body send me the code. Pleae iam waiting for your valuable code.
regards,
suryainstead of asking someone else to do the code and send it to you, why don't you try the code and submit it ot the forum for help?
-
Urgent!!! JText and JButton in same cell of JTable
Does anyone have an example of a JTable with a cell that allows for text input as well as a JButton for invoking the JFileSystemChooser. I believe this involves adding 2 JComponents to a cell within the JTable.
An example of this can be seen if you have Visual Cafe. Under Tools, Environment Options, Virtual Machines. If you click in the cell for the VM Executable then click again (Without double-clicking), a JButton appears that when clicked will invoke the FileSystemChooser. Users have the option of either entering text or invoking the chooser.
thanksYou can create a TableCellEditor your self that inherits from a JPanel that contains a textfield and a button.
class MyCellEditor extends JPanel implements TableCellEditor
JTextField field = new JTextField();
JButton button = new JButton("...");
public MyCellEditor()
// Add a textfield and a jbutton.
this.setLayout(new BorderLayout());
this.add(BorderLayout.CENTER, field);
this.add(BorderLayout.EAST, button);
// Add listeners
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
// Initialize you editor's value.
field.setText(value.toString());
// What else?
return this;
public Object getCellEditorValue()
return field.getText();
// Implements other methods in the interface...
Hope this helps. -
How to put JTextfield and JButton in a cell of JTable
I'm trying to put two Components into one cell of a JTable. This is no
problem (in the TableCellRenderer) unless it comes to editing in these
cells. I have written my own CellEditor for the table.but there is one
minor problem: Neither the JTextfield nor the JButton has the focus so I
can't make any input! Does anybody know what's wrong, please help me for this issue ,plese urgentHere you go
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
public class TableEdit extends JFrame
JTable table = new JTable();
private String[] columnNames = {"non-edit1", "edit", "non-edit2"};
public TableEdit()
super("Table Edit");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
createGUI();
setLocationRelativeTo(null);
setSize(400, 300);
setVisible(true);
private void createGUI()
table.setModel(new DefaultTableModel(3,3)
public int getColumnCount()
return 3;
public boolean isCellEditable(int row, int column)
if(column == 1)
return true;
return false;
public String getColumnName(int column)
return columnNames[column];
public int getRowCount()
return 3;
public Class getColumnClass(int column)
return String.class;
public Object getValueAt(int row, int column)
return row + "" + column;
table.setRowHeight(20);
table.setDefaultEditor(String.class, new MyTableEditor());
JScrollPane sp = new JScrollPane(table);
add(sp);
public class MyTableEditor extends AbstractCellEditor
implements TableCellEditor
JPanel jp = new JPanel(new BorderLayout(5,5));
JTextField tf = new JTextField();
JButton btn = new JButton("...");
public MyTableEditor()
jp.add(tf);
jp.add(btn, BorderLayout.EAST);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
JOptionPane.showMessageDialog(null, "Clicked Lookup");
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
tf.setText(String.valueOf(value));
return jp;
public Object getCellEditorValue()
return tf.getText();
public static void main(String[] parms)
new TableEdit();
} -
Subject:
Subject:
I want to purchase online but they want my security questions answers and I forgot them. Can u please help me in thisif you have forgotten them, contact Apple through iTunes Store Support, and explain that you have forgotten your 3 security questions, that you can reset your password, but doing so doesn't reset your security questions.
-
JButton inside the cell of JTable
JButton buttonInCellOfTable = new JButton();
buttonInCellOfTable.setBackground(Color.RED);
buttonInCellOfTable.setText("MORE");
buttonInCellOfTable.setPreferredSize(new Dimension(10, 22));
buttonInCellOfTable.setMinimumSize(new Dimension(10, 22));
buttonInCellOfTable.setMaximumSize(new Dimension(10, 22));
myJTable.addRow("No. 1", buttonInCellOfTable);
But Color and size isn't shown unlike those are set.
What can I do?* @(#)ButtonTableCellRenderer.java Tiger 2005 April 29
package com.yahoo.ron.table;
import java.awt.Component;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax,swing.JTable;
import javax.swing.table.TableCellRenderer;
* @author Ronillo Ang - [email protected]
final public class ButtonTableCellRenderer extends JButton implements TableCellRenderer{
public ButtonTableCellEditor(ActionListener actionListener){
super("Editor");
if(actionListener == null)
throw new NullPointerException();
addActionListener(actionListener);
public Component getTableCellRenderComponent(JTable table, Object value, boolean selected, boolean hasFocus, int row, int col){
if(value instanceof String){
String text = String.valueOf(value);
setText(text);
else
setText("Unknown value");
return this;
* @(#)TestingButtonTableCellRenderer.java Tiger 2005 April 29
package com.yahoo.ron.test;
import com.yahoo.ron.table.ButtonTableCellRenderer;
import com.yahoo.ron.table.UneditableTableModel;
import com.yahoo.ron.ThreadMonitor;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
* @author Ronillo Ang - [email protected]
* A class to test com.yahoo.ron.table.ButtonTableCellRenderer
public class TestingButtonTableCellRenderer implements ActionListener{
public TestingButtonTableCellRenderer(){
JFrame frame = new JFrame("Testing ButtonTableCellRenderer");
frame.getContentPane().setLayout(new GridLayout(1, 1));
JTable table = new JTable(new UneditableTableModel(new ThreadMonitor()));
TableColumnModel tableColumnModel = table.getColumnModel();
// get the last column.
TableColumn tableColumn = tableColumnModel.getColumn(tableColumnModel.getColumnCount() - 1);
// apply the cell renderer.
tableColumn.setCellRenderer(new ButtonTableCellRenderer(this));
frame.getContentPane().add(new JScrollPane(table));
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
public void actionPerformed(ActionEvent ae){
// do nothing for now.
static public void main(String[] args){
new TestingButtonTableCellRenderer();
// Okie!! I dont include my source of ThreadMonitor.java and UneditableTableModel.
// If problem occur, make some modification. Okie!
// Thanks! God bless you all! -
Control the size for a JButton in a cell of JTable
Hi,
I am trying to add a column buttons on cells of a JTable. I followed the example from http://www.esus.com/docs/GetQuestionPage.jsp?uid=1285 and made it work (thanks).
But, the buttons always resize to fit the column. Is there a way I can set button size, so the button will be smaller?
Any information would be appreciated. Thanks in advance.Use a panel as a renderer and add the button to the panel, and manually set the preferred size of the button yourself. Then when the panel is added to the cell it will be resized, but the button will remain at its preferred size.
-
How to create a textbox and dropdown list in Java similar to google search
Hi,
I want to create a textbox and dropdown in java very much similar to google search . As user types in the letters it should display the dropdown list similar to google. Can anyone help me with this one asap.
Thanks
LavanyaBut my real problem is how to apply the chmod 777 on a folder containing spacesSo why not say so in the first place?
Runtime.exec ("chmod 777 My\\ Folder");Runtime.exec(new String[]{"chmod", "777", "My Folder"});
That is why I chose the example of mkdirYour reasoning on this point is incomprehensible. You wanted help with A so you asked about B. Just wasting time. -
HTHM code iWeb "META NAME and SEARCH" Want change the code
The source HTML from my front page, can i change HTML code "META NAME" and META SEARCH"
i want erase #1 only this and change like exemple #2 Thanks to helm me.
<head>
#1<meta name="Generator" content="iWeb 2.0.4" />
<meta name="iWeb-Build" content="local-build-20090713" />
<meta name="viewport" content="width=900" />
<title>intro</title>
#2 <head>
<title>videos voyage, escapademedia</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="escapade, voyage, voyager, monde, circuits, Inde, Chine, Vietnam, Orient, Asie, Bali, esprit, Tibet, tibétain, monastère, méditation, relaxation, Java, passeport, Inde sacrée, Delhi, billeterie, consultation, monde, itinéraire, Bangkok, temps, projets, dépaysement" />
<meta name="Description" content="escapade, pour voir, sentir, goûter, entendre et toucher le bout du monde; Pour voyager autrement..." />
<meta name="Author" content="www.escapade.com" />
<meta name="ROBOTS" content="INDEX,FOLLOW" />
<meta name="language" content="fr" />
<meta name="revisit-after" content="10 days" />
<meta name="rating" content="General" />
<meta name="category" content="Travel Agency" />Hello Zorig,
>>I want to generate the column as BillingAddress and ShippingAddress
After you added the Address type in the ApplicationUser entity, the Entity Framework would build a 1-1…0 relationship between two entities, you could use the ForeignKey attribute to specify the generated foreign key column name, if your ApplicationUser and
Address have a one…zero to many relationship.
public class ApplicationUser
[Required]
public int SippingAddressID { get; set; }
[Required]
[ForeignKey("SippingAddressID ")]
public Address ShippingAddress { get; set; }
[Required]
public int BillingAddressID { get; set; }
[Required]
[ForeignKey("BillingAddressID ")]
public Address BillingAddress { get; set; }
public int ApplicationUserID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
If they are one..zero to one relationship, in EF, this kind relationship is implemented by mapping primary key, in your case, we cannot specify one primary property to map to two different columns in database.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
I am sending a single-page poster in Illustrator to a commercial printer. There are several placed graphics and I want to choose the correct file-type to keep my Illustrator file nice and small.
Printers like PDFs, but you should consult with the print vendor before you save the file in any particular format. Each vendor is different and have an established workflow. They may not accept JPGs. If the poster prints offset, you will need to supply the appropriate resolution per their request or what they require. If the poster is large format or grand format, then they will or should know what resolution is appropriate. However, large format inkjet only requires 144-150ppi at 100% final size. Try to get in the habit of consulting with the print vendor early on so you end up supplying what is needed.
-
I redeemed a 25 dlls gift card to buy a single song that cost 1.29. Now I want to buy another one and it tells me that I already redeemed that code. What am I doing wrong?
Please try the following steps,
1) Visit the My Apple ID website at:
http://appleid.apple.com
2) If the site is not displayed in your preferred language, click the Change Language link in the upper-right corner, type the name of your language in the field that appears, then click the Save button.
3) Click the "Manage your account" link.
4) Type your iTunes Store account name (which is your Apple ID) in the Apple ID field, type your password in the password field, then click the Sign In button.
5) Click "Addresses" in the column on the left. If you have multiple shipping addresses, remove any out-of-date or duplicate addresses by clicking Delete. Also, make sure the state or province field is filled out correctly for each address. To edit an address, click Edit. Edit all of your shipping addresses and make sure the appropriate state is selected in the State drop-down menus.
6) Now click "Phone Numbers" on the left. The area codes should be in the area code fields and the phone numbers should be in the phone number fields. If an area code is missing, or if it is in a phone number field, your account information may not save properly.
7) Make any other necessary corrections, then click the Save Changes button.
8) Click Log out in the upper-right corner.
When you make your next purchase on the iTunes Store, you will be asked to review your billing information. At this point, you can change your information or simply click Done at the bottom of the screen to proceed. Once you click Done, you should be able to purchase on the iTunes Store using your store credit. -
Left- and right-justifying with dot leaders in JLabel and JButton
Hi,
I am developing checklists using JLabel and JButton components and want to finish up with the text in each component looking something like the following (each line is a separate button/label):
ACTION No1............................RESPONSE No1
ACTION No2............................RESPONSE No2
ACTION No3............................RESPONSE No3
The idea is to have the �Action� text left-justified and the �Response� text right-justified with dot-leaders as shown.
Each text line will be put into its own fixed length label or button.
I plan to construct a string from text blocks �ACTION No1� and �RESPONSE No1� and add the calculated, exact no of dots in between to fill the space.
The text font can be fixed (e.g. Courier) or proportional (e.g. Arial).
My question is how to calculate the number of dots to add to fill the space for different fonts and font sizes.
I think that using FontMetrics could provide some help but am not sure how this would work.
Can anyone help.
Many tks
JohnHi,
I've developed your suggested code further to enable selected JLabels to be toggled visible(true/false) by pressing a JButton.
I'd like however that when a label is made invisible that the rest of the labels/buttons move up to fill the space left by the now invisible label and vice versa.
How do I do this, can you enlighten me on a solution?
Modified code included below. Not very elegant but serves to illustrate the point in question and only makes the label invisible.
Many tks
John
package componentwierd;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ComponentWierd extends JFrame implements ComponentListener, ActionListener {
boolean isVisible = true;
JLabel label2 = new JLabel();
public ComponentWierd() {
getContentPane().setLayout( new GridLayout(0, 1) );
// Using my original suggestion
JLabel label = new JLabel();
label.setLayout(new BorderLayout());
label.add(createWierdComponent());
getContentPane().add(label);
JButton button = new JButton();
button.setLayout(new BorderLayout());
button.add(createWierdComponent());
button.addActionListener(this);
getContentPane().add(button);
// Using Font Metrics
// JLabel label2 = new JLabel("Label2 West...Label2 East");
label2.setText("Label2 West...Label2 East");
label2.addComponentListener( this );
getContentPane().add(label2);
JButton button2 = new JButton("Button2 West...Button2 East");
System.out.println(button2.getIconTextGap());
button2.addComponentListener( this );
button2.setVisible(true);
getContentPane().add(button2);
public void actionPerformed(ActionEvent e) {
if (isVisible == true) {
isVisible = false;
label2.setVisible(false);
} else if (isVisible == false) {
isVisible = true;
label2.setVisible(true);
private JComponent createWierdComponent() {
JPanel panel = new JPanel(new BorderLayout());
panel.setOpaque( false );
panel.add(new JLabel("Label WEST"), BorderLayout.WEST);
panel.add(new JLabel("..............................................."));
panel.add(new JLabel("Label EAST"), BorderLayout.EAST);
return panel;
public void componentResized(ComponentEvent e) {
if (e.getComponent() instanceof JLabel) {
JLabel component = (JLabel)e.getComponent();
String text = component.getText();
String fitText = fitText(component, text);
component.setText( fitText );
if (e.getComponent() instanceof JButton) {
JButton component = (JButton)e.getComponent();
String text = component.getText();
String fitText = fitText(component, text);
component.setText( fitText );
private String fitText(JComponent component, String text) {
// Calculate the total width for painting the text
// (Not sure why I need the -8)
Insets insets = component.getInsets();
int availableWidth = getWidth() - insets.left - insets.right - 8;
// Calculate the minimum width our text will take
String start = text.substring(0, text.indexOf("."));
String middle = "...";
String end = text.substring(text.lastIndexOf(".") + 1);
FontMetrics fm = getFontMetrics( component.getFont() );
int startWidth = fm.stringWidth( start );
int middleWidth = fm.stringWidth( middle );
int endWidth = fm.stringWidth( end );
int minimumWidth = startWidth + middleWidth + endWidth;
// Add dots to fill out the extra space
StringBuffer buffer = new StringBuffer(start);
buffer.append(middle);
if (minimumWidth < availableWidth) {
String dot = ".";
int dotWidth = fm.stringWidth( dot );
int dots = (availableWidth - minimumWidth) / dotWidth;
for (int i = 0; i < dots; i++) {
buffer.append( dot );
buffer.append(end);
String result = buffer.toString();
return result;
public void componentHidden(ComponentEvent e) {}
public void componentMoved(ComponentEvent e) {}
public void componentShown(ComponentEvent e) {}
public static void main(String[] args) {
ComponentWierd frame = new ComponentWierd();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.setSize(200, 200);
frame.setLocationRelativeTo( null );
frame.setVisible(true);
} -
How to print JTextPane containing JTextFields, JLabels and JButtons?
Hi!
I want to print a JTextPane that contains components like JTextFields, JLabels and JButtons but I do not know how to do this. I use the print-method that is available for JTextComponent since Java 1.6. My problem is that the text of JTextPane is printed but not the components.
I wrote this small programm to demonstrate my problem:
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.awt.print.PrinterException;
public class TextPaneTest2 extends JFrame {
private void insertStringInTextPane(String text,
StyledDocument doc) {
try {
doc.insertString(doc.getLength(), text, new SimpleAttributeSet());
catch (BadLocationException x) {
x.printStackTrace();
private void insertTextFieldInTextPane(String text,
JTextPane tp) {
JTextField tf = new JTextField(text);
tp.setCaretPosition(tp.getDocument().getLength());
tp.insertComponent(tf);
private void insertButtonInTextPane(String text,
JTextPane tp) {
JButton button = new JButton(text) {
public Dimension getMaximumSize() {
return this.getPreferredSize();
tp.setCaretPosition(tp.getDocument().getLength());
tp.insertComponent(button);
private void insertLabelInTextPane(String text,
JTextPane tp) {
JLabel label = new JLabel(text) {
public Dimension getMaximumSize() {
return this.getPreferredSize();
tp.setCaretPosition(tp.getDocument().getLength());
tp.insertComponent(label);
public TextPaneTest2() {
StyledDocument doc = new DefaultStyledDocument();
StyledDocument printDoc = new DefaultStyledDocument();
JTextPane tp = new JTextPane(doc);
JTextPane printTp = new JTextPane(printDoc);
this.insertStringInTextPane("Text ", doc);
this.insertStringInTextPane("Text ", printDoc);
this.insertTextFieldInTextPane("Field", tp);
this.insertTextFieldInTextPane("Field", printTp);
this.insertStringInTextPane(" Text ", doc);
this.insertStringInTextPane(" Text ", printDoc);
this.insertButtonInTextPane("Button", tp);
this.insertButtonInTextPane("Button", printTp);
this.insertStringInTextPane(" Text ", doc);
this.insertStringInTextPane(" Text ", printDoc);
this.insertLabelInTextPane("Label", tp);
this.insertLabelInTextPane("Label", printTp);
this.insertStringInTextPane(" Text Text", doc);
this.insertStringInTextPane(" Text Text", printDoc);
tp.setEditable(false);
printTp.setEditable(false);
this.getContentPane().add(tp);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400,400);
this.setVisible(true);
JOptionPane.showMessageDialog(tp, "Start printing");
try {
tp.print();
} catch (PrinterException e) {
e.printStackTrace();
try {
printTp.print();
} catch (PrinterException e) {
e.printStackTrace();
public static void main(String[] args) {
new TextPaneTest2();
}First the components are shown correctly in JTextPane, but when printing is started they vanish. So I created another textPane just for printing. But this does not work either. The components are not printed. Does anybody know how to solve this?
Thanks!I do not know how I should try printComponent. From the API-Doc of JComponent of printComponent: This is invoked during a printing operation. This is implemented to invoke paintComponent on the component. Override this if you wish to add special painting behavior when printing. The method print() in JTextComponent is completely different, it starts the print-job. I do not understand how to try printComponent. It won't start a print-job.
-
I participated in getting the free download of Mountain Lion for new Mac owners. It took me three days to finally get a code to do it and when I tried downloading it, the estimated time was 74 days 17 hours. Now an error occurred. What do I do? I am very frustrated and just want the great software to download in a resonalbe time!
Take your Mac to a location with a fast, relaible Internet connection that will be all yours during the duration of the download.
If you want to complain, PLEASE call Apple and do so.
Internet only downloads of OS X is completely stupid, it assumes everyone has reliable Internet everywhere and /or no data caps. -
Placed Files and Copied Text not Appearing in Links Palette
I am working on an annual report.
The report is a booklet. I'm using master text boxes. The report is basically one, long flowing stream of text. Within this there are many articles, divided by headings.
I'm receiving articles for this annual report from many different sources, text within emails, Word documents, etc.
I have the "Create Links When Placing Text and Spreadsheet Files" checked.
I'm having this issue:
Nothing is appearing in my Links palette.
When I go to File>Place, and place a Word document in as an article within my report, it doesn't appear in the link palette. When I copy text in from a Word document, it doesn't appear in the link palette.
However, when I place the Word document in the annual report within it's own text box, THEN it appears in the links palette.
But I don't want each Word document within it's own text box, I want it to be a part of the other text flow within the report.
Is there something I'm doing wrong?
Can't InDesign retain the link to the document even if the text is placed within a larger body of text flow?No. It's not possible to maintain a link to text that's not in its own text frame.
What would happen if you were to edit the text in the frame, and part of the text affected was linked and part was not. What would you expect to happen? Such a workflow isn't possible as far as I know.
Maybe you are looking for
-
Settlement Discount on Credit note
Hi All, I have a client running 2005A SP01 PL 20 and no settlement discount is being calculated on credit notes when they select them as part of an incoming payment. The payment term with a cash discount is linked to the credit, but the discount val
-
Trying to understand how many computers I can download Lightroom 5 on??
I currently have LR 5 downloaded and activated on my laptop, which is starting to wear down (making LR slower). From what I've read so far online, I can deactivate LR on my laptop and activate it on only one more computer/laptop (If I'm reading thin
-
Error when importing Word document
I am having a problem importing a Word document. This is the first time I have experienced the problem. Partway through the import (it appears to be attempting to open the Word document) I get a message: A file error has occurred. Try one or more of
-
Why can't ibook give meaning of words in other languages like Arabic?
Why can't ibook give meaning of words in other languages like Arabic?
-
I am making a cartoon, which was created in FLASH, Then the SWF's were put into After Effects and exported out as MOV's. (I've tried both AppleProRes4444 and Animation codecs). Then I put those Mov's into Premiere. Everything looks crisp until I rend