I wish to implement a button to every row in my for-loop. But i have no idea how to do it.
I would like to be able to edit data in each row by pressing a button.
for(HentbestillingsordreRegistrer hentboregistrer: hbor){
if(status.equals("Leveret")){
temp.append("<html>");
temp.append("BestillingsID: ");
temp.append(hentboregistrer.BestillingsID);
temp.append("<br />");
temp.append("Ordre Status:");
temp.append(hentboregistrer.BestillingsStatus);
temp.append("<br />");
temp.append("LeverandoerID: ");
temp.append(hentboregistrer.Leverandoernavn);
temp.append("<br />");
temp.append("Modtaget af: ");
temp.append(hentboregistrer.ModtagetAf);
temp.append("<br />");
temp.append("<br />");
}else{
temp.append("<html>");
temp.append("BestillingsID: ");
temp.append(hentboregistrer.BestillingsID);
temp.append("<br />");
temp.append(hentboregistrer.BestillingsStatus);
temp.append("<br />");
temp.append("LeverandoerID: ");
temp.append(hentboregistrer.Leverandoernavn);
temp.append("<br />");
temp.append("Modtaget af: ");
temp.append(hentboregistrer.ModtagetAf);
temp.append("<br />");
temp.append("<br />");
}
}
return temp.toString();
}
public JPanel HentOrdreGUI(){
JPanel info = new JPanel();
info.setLayout(new BorderLayout());
JLabel labelprintdata = new JLabel(temp.toString());
JScrollPane scroll = new JScrollPane(labelprintdata);
info.add(scroll, BorderLayout.CENTER);
return info;
}
I would change the JLabel into a JTable, and add a JButton as the 3rd column of the table. Something like this...
// Create a container for all your table data.
// There are 3 columns (type, value, button) in the table.
// And each order has 4 items in it (BestillingsId, Status, LeverandoerID, Modtaget)
Object[][] tableData = new Object[numOrders*4][3];
for(int i=0;i<numOrders;i++){
HentbestillingsordreRegistrer hentboregistrer = hbor[i];
// For each order, we need to add 4 rows, each with 3 cells in it (to hold the type, value, and the button)
if(status.equals("Leveret")){
tableData[(i*4)+0] = new Object[]{"BestillingsID",hentboregistrer.BestillingsID,new JButton("Edit")};
tableData[(i*4)+1] = new Object[]{"Ordre Status",hentboregistrer.BestillingsStatus,new JButton("Edit")};
tableData[(i*4)+2] = new Object[]{"LeverandoerID",hentboregistrer.Leverandoernavn,new JButton("Edit")};
tableData[(i*4)+3] = new Object[]{"Modtaget af:",hentboregistrer.ModtagetAf,new JButton("Edit")};
}
else{
tableData[(i*4)+0] = new Object[]{"BestillingsID",hentboregistrer.BestillingsID,new JButton("Edit")};
tableData[(i*4)+1] = new Object[]{"Ordre Status",hentboregistrer.BestillingsStatus,new JButton("Edit")};
tableData[(i*4)+2] = new Object[]{"LeverandoerID",hentboregistrer.Leverandoernavn,new JButton("Edit")};
tableData[(i*4)+3] = new Object[]{"Modtaget af:",hentboregistrer.ModtagetAf,new JButton("Edit")};
}
}
// Headings for the table columns
String[] tableHeadings = new String[]{"Type","Value","Button"};
JPanel info = new JPanel();
info.setLayout(new BorderLayout());
// Create the table from the data above
JTable table = new JTable(tableData,tableHeadings);
JScrollPane scroll = new JScrollPane(table);
info.add(scroll, BorderLayout.CENTER);
Related
I am trying to create a simple menu interface with 4 rows of various buttons and labels using GridLayout with FlowLayout inside each grid for organising the elements. However the space for the buttons and labels which should only take 1 line takes up a huge amount of space.
This is what my interface looks like minimized:
This is what it looks like maximized:
I am looking to set the maximum size of the labels panels/grid so that it only takes a small amount of space.
I am trying to make all the elements visible without anything being hidden with as small a window size as possible like this:
This is my code:
public class Window extends JFrame{
public Window() {
super("TastyThai Menu Ordering");
}
public static void main(String[] args) {
Window w = new Window();
w.setSize(500, 500);
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel title = new JLabel("TastyThai Menu Order", SwingConstants.CENTER);
title.setFont(title.getFont().deriveFont(32f));
//generate page title
Container titlePanel = new JPanel(); // used as a container
titlePanel.setBackground(Color.WHITE);
FlowLayout flow = new FlowLayout(); // Create a layout manager
titlePanel.setLayout(flow);// assign flow layout to panel
titlePanel.add(title); // add label to panel
w.getContentPane().add(BorderLayout.NORTH,titlePanel);
//generate row containers
Container r1 = new JPanel(new FlowLayout());
Container r2 = new JPanel(new FlowLayout());
Container r3 = new JPanel(new FlowLayout());
Container r4 = new JPanel(new FlowLayout());
//generate mains radio buttons
Container mains = new JPanel(new GridLayout(7, 0));
mains.setBackground(Color.RED);
JLabel mainsHeader = new JLabel("Mains");
mains.add(mainsHeader);
String[] mainsChoices = {"Vegetarian", "Chicken", "Beef", "Pork", "Duck", "Seafood Mix"};
JRadioButton[] mainsRadioButton = new JRadioButton[6];
ButtonGroup mainsButtons = new ButtonGroup();
for(int i = 0; i < mainsChoices.length; i++) {
mainsRadioButton[i] = new JRadioButton(mainsChoices[i]);
mains.add(mainsRadioButton[i]);
mainsButtons.add(mainsRadioButton[i]);
}
//generate noodles radio buttons
Container noodles = new JPanel(new GridLayout(7, 0));
noodles.setBackground(Color.GREEN);
JLabel noodlesHeader = new JLabel("Noodles");
noodlesHeader.setFont(noodlesHeader.getFont().deriveFont(24f));
noodles.add(noodlesHeader);
String[] noodlesChoices = {"Pad Thai", "Pad Siew", "Ba Mee"};
JRadioButton[] noodlesRadioButton = new JRadioButton[3];
ButtonGroup noodlesButtons = new ButtonGroup();
for(int i = 0; i < noodlesChoices.length; i++) {
noodlesRadioButton[i] = new JRadioButton(noodlesChoices[i]);
noodles.add(noodlesRadioButton[i]);
noodlesButtons.add(noodlesRadioButton[i]);
}
//generate sauces radio buttons
Container sauces = new JPanel(new GridLayout(7, 0));
sauces.setBackground(Color.BLUE);
JLabel saucesHeader = new JLabel("Sauce");
saucesHeader.setFont(saucesHeader.getFont().deriveFont(24f));
sauces.add(saucesHeader);
String[] saucesChoices = {"Soy Sauce", "Tamarind Sauce"};
JRadioButton[] saucesRadioButton = new JRadioButton[2];
ButtonGroup saucesButtons = new ButtonGroup();
for(int i = 0; i < saucesChoices.length; i++) {
saucesRadioButton[i] = new JRadioButton(saucesChoices[i]);
sauces.add(saucesRadioButton[i]);
saucesButtons.add(saucesRadioButton[i]);
}
//generate extras check boxes
Container extras = new JPanel(new GridLayout(7, 0));
extras.setBackground(Color.YELLOW);
JLabel extrasHeader = new JLabel("Extra");
extrasHeader.setFont(extrasHeader.getFont().deriveFont(24f));
extras.add(extrasHeader);
String[] extrasChoices = {"Mushroom", "Egg", "Broccoli", "Beansrpout", "Tofu"};
JCheckBox[] extrasBoxes = new JCheckBox[5];
for(int i = 0; i < extrasChoices.length; i++) {
extrasBoxes[i] = new JCheckBox(extrasChoices[i]);
extras.add(extrasBoxes[i]);
}
JLabel selectionPrice = new JLabel("Selection Price: $ ");
JLabel selectionPriceVal = new JLabel("_______________");
JButton addToOrder = new JButton("Add to Order");
JLabel totalPrice = new JLabel("Total Price: $ ");
JLabel totalPriceVal = new JLabel("_______________");
JButton clearOrder = new JButton("Clear Order");
JRadioButton pickUp = new JRadioButton("Pick Up");
JRadioButton delivery = new JRadioButton("Delivery");
ButtonGroup pickupDelivery = new ButtonGroup();
pickupDelivery.add(pickUp);
pickupDelivery.add(delivery);
JButton completeOrder = new JButton("Complete Order");
Container menuSelection = new JPanel(new GridLayout(4,0));
menuSelection.add(r1);
r1.add(mains);
r1.add(noodles);
r1.add(sauces);
r1.add(extras);
menuSelection.add(r2);
r2.add(selectionPrice);
r2.add(selectionPriceVal);
r2.add(addToOrder);
menuSelection.add(r3);
r3.add(totalPrice);
r3.add(totalPriceVal);
r3.add(clearOrder);
menuSelection.add(r4);
r4.add(pickUp);
r4.add(delivery);
r4.add(completeOrder);
w.getContentPane().add(BorderLayout.CENTER, menuSelection);
w.setVisible(true);
}
}
GridLayout does not support that. All rectangles have the same size.
Take a look at the GridBagLayout, which supports dynamic resizing and much more.
I need to change my label's distribution on a JTabbedPane.
I have this:
And I want to do this:
Can someone help me?
I post the code below:
tabbedResultsPane = new JTabbedPane(SwingConstants.TOP);
JPanel featurePanel = new JPanel(new GridLayout(TOTAL_FEATURES, 2, 3, 3));
estadoScroll = new JScrollPane(featurePanel,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
lblFeatureHdr = new JLabel[TOTAL_FEATURES];
lblFeature = new JLabel[TOTAL_FEATURES];
for(int i=0; i<TOTAL_FEATURES; i++)
{
lblFeatureHdr[i] = new JLabel(strHeader[i], JLabel.RIGHT);
lblFeatureHdr[i].setOpaque(true);
lblFeatureHdr[i].setBackground(new Color(220,255,220));//.lightGray);
lblFeature[i] = new JLabel("", JLabel.LEFT);
lblFeature[i].setForeground(Color.blue);// black);
featurePanel.add(lblFeatureHdr[i]);
featurePanel.add(lblFeature[i]);
}
Define 4 columns GridLayout (rather than 2 columns you have).
and correct your code yo add 2 more labels for each row.
for(int i=0; i<TOTAL_FEATURES; i++)
{
lblFeatureHdr[i] = new JLabel(strHeader[i], JLabel.RIGHT);
lblFeatureHdr[i].setOpaque(true);
lblFeatureHdr[i].setBackground(new Color(220,255,220));//.lightGray);
lblFeature[i] = new JLabel("", JLabel.LEFT);
lblFeature[i].setForeground(Color.blue);// black);
featurePanel.add(lblFeatureHdr[i]);
featurePanel.add(lblFeature[i]);
// add 2 more lables to the same row
JLabel l=new JLabel(strHeader[i], JLabel.RIGHT);
l.setBackground(new Color(220,255,220));//.lightGray);
featurePanel.add(l);
featurePanel.add(new JLabel("", JLabel.LEFT));
}
I added MouseListener to select a particular row from table,the content of row is getting printed on console but I want to print this content on new frame what should I do for this.
I attached my code along with the screenshot of the table.
thanks for help.
This is my code.
final JTable table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane( table );
cp.add(scrollPane,BorderLayout.CENTER);
frame.add(cp);
frame.setSize(300,300);
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible(true);
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e){
if(e.getClickCount()==1){
JTable target = (JTable)e.getSource();
System.out.println(target);
int row = target.getSelectedRow();
System.out.println(row);
Object [] rowData = new Object[table.getColumnCount()];
Object [] colData = new Object[table.getRowCount()];
for(int j = 0;j < table.getRowCount();j++)
for(int i = 0;i < table.getColumnCount();i++)
{
rowData[i] = table.getValueAt(j, i);
System.out.println(rowData[i]);
}
}
}
});
}
First of all, if you make a graphical interface with swing, you can't use System.out.print.
You need to set every row in a Label and print it out that way. If it is a Label then you can select it with your mouse
In the Mouse Listener method, Call the new JFrame,
in that JFrame , put the Contents of selected Row to Constructor Parameters.
JFrame newframe=new JFrame("Selected Contents);
When you output the result (System.out.println(rowData[i]);) just create a new JFrame and place the text you want to output here :
...
JFrame secondFrame = new JFrame();
JPanel myPanel = new JPanel();
for(int j = 0;j < table.getRowCount();j++){
for(int i = 0;i < table.getColumnCount();i++){
rowData[i] = table.getValueAt(j, i);
JLabel label = new JLabel(rowData[i]);
myPanel.add(label);
}
}
secondFrame.add(myPanel);
secondFrame.setVisible(true);
....
Good afternoon. I have created an application for an introductory java course that allows a user to sort their DVD collection by title, studio, or year. The application also allows the user to add additional DVD's to their collection, thus enlarging their arrays. The code properly compiles, but there is clearly something wrong as the titles, studio, and years are mixing themselves up. To be clear, this code is from a textbook and is part of a lab that requires the use of the exact methods, packages, etc. that you see in the code. I'm not asking for advice on how to make the code more efficient (although that is welcome as I am learning), but specifically what is wrong with the code provided causing the "scramble". Here is the code I have:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class DVD extends JFrame implements ActionListener
{
// construct components
JLabel sortPrompt = new JLabel("Sort by:");
JComboBox fieldCombo = new JComboBox();
JTextPane textPane = new JTextPane();
// initialize data in arrays
String title[] = {"Casablanca", "Citizen Kane", "Singin' in the Rain", "The Wizard of Oz"};
String studio[] = {"Warner Brothers", "RKO Pictures", "MGM", "MGM"};
String year[] = {"1942", "1941", "1952", "1939"};
// construct instance of DVD
public DVD()
{
super("Classics on DVD");
}
// create the menu system
public JMenuBar createMenuBar()
{
// create an instance of the menu
JMenuBar mnuBar = new JMenuBar();
setJMenuBar(mnuBar);
// construct and populate the File menu
JMenu mnuFile = new JMenu("File", true);
mnuFile.setMnemonic(KeyEvent.VK_F);
mnuFile.setDisplayedMnemonicIndex(0);
mnuBar.add(mnuFile);
JMenuItem mnuFileExit = new JMenu("Exit");
mnuFileExit.setMnemonic(KeyEvent.VK_X);
mnuFileExit.setDisplayedMnemonicIndex(1);
mnuFile.add(mnuFileExit);
mnuFileExit.setActionCommand("Exit");
mnuFileExit.addActionListener(this);
// contruct and populate the Edit menu
JMenu mnuEdit = new JMenu("Edit", true);
mnuEdit.setMnemonic(KeyEvent.VK_E);
mnuEdit.setDisplayedMnemonicIndex(0);
mnuBar.add(mnuEdit);
JMenuItem mnuEditInsert = new JMenuItem("Insert New DVD");
mnuEditInsert.setMnemonic(KeyEvent.VK_I);
mnuEditInsert.setDisplayedMnemonicIndex(0);
mnuEdit.add(mnuEditInsert);
mnuEditInsert.setActionCommand("Insert");
mnuEditInsert.addActionListener(this);
JMenu mnuEditSearch = new JMenu("Search");
mnuEditSearch.setMnemonic(KeyEvent.VK_R);
mnuEditSearch.setDisplayedMnemonicIndex(3);
mnuEdit.add(mnuEditSearch);
JMenuItem mnuEditSearchByTitle = new JMenuItem("by Title");
mnuEditSearchByTitle.setMnemonic(KeyEvent.VK_T);
mnuEditSearchByTitle.setDisplayedMnemonicIndex(3);
mnuEditSearch.add(mnuEditSearchByTitle);
mnuEditSearchByTitle.setActionCommand("title");
mnuEditSearchByTitle.addActionListener(this);
JMenuItem mnuEditSearchByStudio = new JMenuItem("by Studio");
mnuEditSearchByStudio.setMnemonic(KeyEvent.VK_S);
mnuEditSearchByStudio.setDisplayedMnemonicIndex(3);
mnuEditSearch.add(mnuEditSearchByStudio);
mnuEditSearchByStudio.setActionCommand("studio");
mnuEditSearchByStudio.addActionListener(this);
JMenuItem mnuEditSearchByYear = new JMenuItem("by Year");
mnuEditSearchByYear.setMnemonic(KeyEvent.VK_Y);
mnuEditSearchByYear.setDisplayedMnemonicIndex(3);
mnuEditSearch.add(mnuEditSearchByYear);
mnuEditSearchByYear.setActionCommand("year");
mnuEditSearchByYear.addActionListener(this);
return mnuBar;
}
// create the content pane
public Container createContentPane()
{
// populate the JComboBox
fieldCombo.addItem("Title");
fieldCombo.addItem("Studio");
fieldCombo.addItem("Year");
fieldCombo.addActionListener(this);
fieldCombo.setToolTipText("Click the drop-down arrow to display sort fields.");
// construct and populate the north panel
JPanel northPanel = new JPanel();
northPanel.setLayout(new FlowLayout());
northPanel.add(sortPrompt);
northPanel.add(fieldCombo);
// create the JTextPane and center panel
JPanel centerPanel = new JPanel();
setTabsAndStyles(textPane);
textPane = addTextToTextPane();
JScrollPane scrollPane = new JScrollPane(textPane);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(500, 200));
centerPanel.add(scrollPane);
// create Container and set attributes
Container c = getContentPane();
c.setLayout(new BorderLayout(10,10));
c.add(northPanel,BorderLayout.NORTH);
c.add(centerPanel,BorderLayout.CENTER);
return c;
}
// method to create tab stops and set font styles
protected void setTabsAndStyles(JTextPane textPane)
{
// create Tab Stops
TabStop[] tabs = new TabStop[2];
tabs[0] = new TabStop(200, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
tabs[1] = new TabStop(350, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
TabSet tabset = new TabSet(tabs);
// set Tab Style
StyleContext tabStyle = StyleContext.getDefaultStyleContext();
AttributeSet aset =
tabStyle.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset);
textPane.setParagraphAttributes(aset, false);
// set Font styles
Style fontStyle =
StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
Style regular = textPane.addStyle("regular", fontStyle);
StyleConstants.setFontFamily(fontStyle, "SansSerif");
Style s = textPane.addStyle("italic", regular);
StyleConstants.setItalic(s, true);
s = textPane.addStyle("bold", regular);
StyleConstants.setBold(s, true);
s = textPane.addStyle("large", regular);
StyleConstants.setFontSize(s, 16);
}
// method to add new text to the JTextPane
public JTextPane addTextToTextPane()
{
Document doc = textPane.getDocument();
try
{
// clear the previous text
doc.remove(0, doc.getLength());
// insert title
doc.insertString(0,"TITLE\tSTUDIO\tYEAR\n",textPane.getStyle("large"));
// insert detail
for (int j = 0; j<title.length; j++)
{
doc.insertString(doc.getLength(), title[j] + "\t", textPane.getStyle("bold"));
doc.insertString(doc.getLength(), studio[j] + "\t", textPane.getStyle("italic"));
doc.insertString(doc.getLength(), year[j] + "\t", textPane.getStyle("regular"));
}
}
catch(BadLocationException ble)
{
System.err.println("Couldn't insert text.");
}
return textPane;
}
// event to process user clicks
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
// user clicks the sort by combo box
if (e.getSource() == fieldCombo)
{
switch(fieldCombo.getSelectedIndex())
{
case 0:
sort(title);
break;
case 1:
sort(studio);
break;
case 2:
sort(year);
break;
}
}
// user clicks Exit on the File menu
if (arg == "Exit")
System.exit(0);
// user clicks Insert New DVD on the Edit Menu
if (arg == "Insert")
{
// accept new data
String newTitle = JOptionPane.showInputDialog(null, "Please enter the new movie's title");
String newStudio = JOptionPane.showInputDialog(null, "Please enter the studio for " + newTitle);
String newYear = JOptionPane.showInputDialog(null, "Please enter the year for " + newTitle);
// enlarge arrays
title = enlargeArray(title);
studio = enlargeArray(studio);
year = enlargeArray(year);
// add new data to arrays
title[title.length-1] = newTitle;
studio[studio.length-1] = newStudio;
year[year.length-1] = newYear;
// call sort method
sort(title);
fieldCombo.setSelectedIndex(0);
}
// user clicks Title on the Search submenu
if (arg == "title")
search(arg, title);
// user clicks Studio on the Search submenu
if (arg == "studio")
search(arg, studio);
// user clicks Year on the Search submenu
if (arg == "year")
search(arg, year);
}
// method to enlarge an array by 1
public String[] enlargeArray(String[] currentArray)
{
String[] newArray = new String[currentArray.length + 1];
for (int i = 0; i<currentArray.length; i++)
newArray[i] = currentArray[i];
return newArray;
}
// method to sort arrays
public void sort(String tempArray[])
{
// loop ton control number of passes
for (int pass = 1; pass < tempArray.length; pass++)
{
for (int element = 0; element < tempArray.length - 1; element++)
if (tempArray[element].compareTo(tempArray[element + 1])>0)
{
swap(title, element, element + 1);
swap(studio, element, element + 1);
swap(year, element, element + 1);
}
}
addTextToTextPane();
}
// method to swap two elements of an array
public void swap(String swapArray[], int first, int second)
{
String hold; // temporary holding area for swap
hold = swapArray[first];
swapArray[first] = swapArray[second];
swapArray[second] = hold;
}
public void search(String searchField, String searchArray[])
{
try
{
Document doc = textPane.getDocument(); // assign text to document object
doc.remove(0,doc.getLength()); // clear previous text
// display column titles
doc.insertString(0,"TITLE\tSTUDIO\tYEAR\n",textPane.getStyle("large"));
// prompt user for search data
String search = JOptionPane.showInputDialog(null, "Please enter the "+searchField);
boolean found = false;
// search arrays
for (int i = 0; i<title.length; i++)
{
if (search.compareTo(searchArray[i])==0)
{
doc.insertString(doc.getLength(), title[i] + "\t", textPane.getStyle("bold"));
doc.insertString(doc.getLength(), studio[i] + "\t", textPane.getStyle("italic"));
doc.insertString(doc.getLength(), year[i] + "\t", textPane.getStyle("regular"));
found = true;
}
}
if (found == false)
{
JOptionPane.showMessageDialog(null, "Your search produced no results.","No results found",JOptionPane.INFORMATION_MESSAGE);
sort(title);
}
}
catch(BadLocationException ble)
{
System.err.println("Couldn't insert text.");
}
}
// main method executes at run time
public static void main(String arg[])
{
JFrame.setDefaultLookAndFeelDecorated(true);
DVD f = new DVD();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setJMenuBar(f.createMenuBar());
f.setContentPane(f.createContentPane());
f.setSize(600,375);
f.setVisible(true);
}
}
Here is a screenshot to give you a sense of what I mean be "scrambled".
Obviously, all of the titles should be in the title column, studios in studio, and years in year.
As always, I appreciate the guidance.
The problem is this line
doc.insertString(doc.getLength(), year[j] + "\t", textPane.getStyle("regular"));
where you put a tab ("\t") after the year but instead you want a newline ("\n"). So the line becomes
doc.insertString(doc.getLength(), year[j] + "\n", textPane.getStyle("regular"));
Do you simply miss a newline after adding the year of a DVD to the document? I.e.
doc.insertString(doc.getLength(), year[j] + "\n", textPane.getStyle("regular"));
I want to create a column and install a button in this last column in this table.
public JPanel pinakas(String[] pinaka) {
int sr = 0;
//int ari8mos =0;
String[] COLUMN_NAMES = {"Κωδικός", "Ποσότητα", "Τιμή", "Περιγραφή", "Μέγεθος", "Ράτσα"};
//pio panw mporoume na pros8esoume ws prwto column to "#", wste na deixnei ton ari8mo ths ka8e kataxwrhshs
DefaultTableModel modelM = new DefaultTableModel(COLUMN_NAMES, 0);
JTable tableM = new JTable(modelM);
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(new JScrollPane(tableM), BorderLayout.CENTER);
Display disp = new Display();
while (pinaka[sr] != null) // !!!!tha ektupwsei kai mia parapanw "/n" logo ths kataxwrhshs prwtou h teleytaiou mahmatos
{
String[] temp5 = disp.lineDelimiter(pinaka[sr],6, "#");
Object[] doge = { temp5[0], temp5[1], temp5[2], temp5[3], temp5[4], temp5[5]};//edw mporoume sthn arxh na valoume to ari8mos gia na fainetai o ari8mos twn kataxwrhsewn
modelM.addRow(doge);
sr++;
//ari8mos++;
}
return mainPanel;
}
Table Button Column shows one possible solution.