Displaying a matrix in Swing

Hi all,
Is there anybody who knows a easy way of displaying a matrix in Swing. It can be done by declaring a lot of buttons (64 buttons in a 8x8 matrix) and than displaying them, but there has to be a better way. Any suggestions
Greetings.
Vincent

You could use AWT or Java2D graphics to display them within a JPanel. Just override the paintComponent(Graphics g) method (don't forget to call super.paintComponent(g) first) and do the drawing in there.
If you need interaction, you could implement a MouseMotionListener and MouseListener to see over which element the mouse is over and in which a mouse button was clicked (or even double-clicked).
class MyMatrixPanel extends JPanel implements MouseListener, MouseMotionListener {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.white);
g.fillRect(0,0,this.getWidth(),this.getHeight());
g.setColor(Color.black);
for(int i = 0; i < number_of_rows+1; i++) {
g.drawLine(x1,y1,x2,y2);
g.drawString("m00",x,y);
for(int i = 0; i < number_of_columns+1; i++)
g.drawLine(x1,y1,x2,y2);
The JPanel will need to be added to a JFrame, JDialog, or similar. You'll have to supply the coordinates, and of course this is skeletal. Let me know if this helps and if you need more info.
Robert Templeton

Similar Messages

  • Displaying a matrix in swing----HELP!! :)

    Hello I want to print out values from a matrix in some sort of table.
    javax.swing.JTable is almost what I want, but you can't do row labels (only column labels, I think)--
    Are there any classes like JTable, but a little more like an Excel spreadsheet where you have labels on the columns and rows???
    Or any other suggestions for displaying matrix values with swing would be helpful!!
    THANKS!!!!

    .

  • Display Unicode Character in Swing Objects

    I am trying to display Chinese Characters using Swing GUI.
    I created Unicode strings using escape character \uXXXX
    I displayed \u4e00 successfully
    However when I tried to display \ub8db i got a square box displayed instead.
    I am using: Winnt ver 4 ,RichWin 97
    private Object listData[] = {
    new String("\ucfe3\ub8db"), // Two boxes displayed in list
    new String("\u4e01\u4e00"), // Characters displayed correctly
    new String("Third selection")
    To hope to get some replies ASAP. Thanks!!!
    Regards,
    Patrick

    Hi Patrick,
    Yeh, fonts are rather ubiquitous when it comes to internationalization. The fact that the font.properties files still exist confuses a lot of people. In reality, Sun doesn't support them any more, and they aren't all that useful if you're actually deploying your code onto other machines.
    So, to answer your questions... :D
    1) Each component will have a font set on it. To start with, each component will end up with the JDK default, usually the Dialog font in Java. From memory, I think this maps to Arial on Windows systems, though I'm not sure if RichWin alters this in anyway, as I haven't used it myself.
    You can check the available fonts on your machine by calling:
    GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    This returns an array of strings. You can basically create a new font from any of the names that appear in here. For instance, if one of the strings was "Arial Bold", you could create the following font:
    Font myFont = new Font("Arial Bold", Font.PLAIN, 12);
    2) The best way is to simply create the font you want on startup. If you can't rely on the font
    you need being installed on every machine you plan to run your program on, the best solution is to either install it on startup, or carry it around with you.
    Have a look at Font.createFont(), as it allows you to create a new Font object from a *.TTF file (a TrueType font). In JDK1.3, this is buggy, leaving a large temp file behind every time you run it, but I've already tried this under Merlin Beta, and it's fixed and working fine.
    The reason this is handy is because the font we keep talking about on here, Arial Unicode MS, is a TrueType font. So you can carry the font around with you, and load it on startup using this call.
    Arial Unicode MS is a 23Mb font, but it's capable of displaying just about any character you could imagine.
    The trick from there, once you've loaded your font, is to make sure you call setFont() on just about any component you create. Menus are a cow - you've got to listen for events, as the dropdown menus don't always get the font straight away. But other than that, it's fairly simple.
    3) The short answer is to call the getAvailableFontFamilyNames() call above, and look for any familiar font names. If you can't find any, you know you're not going to be able to display anything.
    Windows seems to have standard fonts for the international languages. In Chinese, this is SimHei for Simplified (mainland) Chinese, and MingLiU for Traditional (Taiwanese) Chinese. Simplified covers about 30,000 Kanji, while Traditional covers around 80,000.
    So for Chinese, you would look for "SimHei" and "MingLiU", plus any of the fonts capable of displaying anything, like "Arial Unicode MS". If none of these strings are in the array, you may want to carry the Arial Unicode MS installer around with you and execute it. This file is about 11Mb, and is available as a download off the Microsoft website.
    4) Probably about the most useful thing I've come across is the Sun I18N tutorial on this very website. There isn't a heck of a lot out there, unfortunately. About the only other things I can recommend are http://www.unicode.org for the Unicode character codes, and http://www.njstar.com for NJStar Communicator, which you'll find useful if you're working with Chinese.
    Oh, and watch this forum, of course. ;D
    Hope that helps!
    Martin Hughes

  • Displaying a matrix on a Forms 6 form

    Guys:
    I'm trying to figure out a way to display
    a matrix on a form with three fields
    2 text items and 1 check box eg.
    Dept
    ====
    Emp Finance Projects Transport ...
    ===
    John X
    Tom X
    Sam X
    Pete X X
    Any ideas???
    Thanks!
    Abhay

    Hi
    I had similar problem. May be my dicision will be helpfull for you.
    There are table (for simplicity) sheet(emp, day, job) with the primary key(emp, day). It's needed matrix with X axis as 'emp', Y axis as 'day' (for a one month) and 'job' as the cell.
    I created block SHEET_BLOCK with the items: EMP, DAY_01, DAY_02, ..., DAY_31. 'Query Data Souce Name' is:
    SELECT emp FROM sheet;
    EMP is the 'Database Item', but another (DAY_??) aren't 'Database Item'.
    Cteated POST_QUERY trigger for populating fields DAY_??:
    DECLARE
    v_dest_item VARCHAR2(80);
    v_rec_num NUMBER;
    CURSOR c_emp_day_job IS
    SELECT day, job
    FROM sheet
    WHERE emp = :SHEET_BLOCK.EMP
    BEGIN
    IF :System.Mode != 'QUERY' THEN
    RETURN;
    END IF;
    FOR v_emp_day_job IN c_emp_day_job LOOP
    v_dest_item := ':SHEET_BLOCK.DAY_' &#0124; &#0124; v_emp_day_job.day;
    COPY( v_emp_day_job.job, v_dest_item );
    END LOOP;
    END;
    Andrew.

  • Displaying image on the swings application

    Hi All,
    I want to display images onto my swing application. I was using ImageIcon and Class to getResource(filename). It can only provide me images that i have placed in my package not outside my package.
    Please help me, how to to do?
    Thanks in advance.

    [url http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html]How to Use Icons

  • Displaying a matrix onto screen

    hi guys, i'm trying to make a game. i'm going to load a two dimensional array with images and then display the whole matrix onto the screen and then add stuff to it like mouselistener.
    static Object image[][] = new Object[300][300];
    i only have a frame now. Can anyone teach me how to display the matrix?

    If you know the 2D API, full screen mode only involves a few more method calls, and a switch to active rendering:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    public class FlipExample extends Window {
        public static void main(String[] args) throws Exception {
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice gd = ge.getDefaultScreenDevice();
            try {
                FlipExample w = new FlipExample();
                gd.setFullScreenWindow(w);
                w.animate();
            } catch(Exception e) {
                e.printStackTrace();
                throw e;
            } finally {
                gd.setFullScreenWindow(null);
                System.exit(0);
        private boolean quit = false;
        private BufferedImage orig;
        private int offset = 0, x, dx=2, y, dy=2, UBX, UBY;
        public FlipExample() throws IOException {
            super(new Frame());
            setIgnoreRepaint(true);
            addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent e) {
                    if (e.getClickCount() > 1)
                        quit = true;
            orig = ImageIO.read(new URL("http://today.java.net/jag/bio/JagHeadshot-small.jpg"));
        public void animate() {
            createBufferStrategy(2);
            BufferStrategy bs = getBufferStrategy();
            UBX = getWidth()-orig.getWidth();
            UBY = getHeight()-orig.getHeight();
            for(int times=0; !quit && times<10000; ++times)
                render(bs);
        private void render(BufferStrategy bs) {
            Graphics2D g = (Graphics2D) bs.getDrawGraphics();
            g.fillRect(0, 0, getWidth(), getHeight());
            g.drawRenderedImage(orig, AffineTransform.getTranslateInstance(x, y));
            bs.show();
            x += dx;
            if (x<0 | x>UBX)
                dx *= -1;
            y += dy;
            if (y<0 | y>UBY)
                dy *= -1;

  • How to Display an Image in swing

    I Want to display an image in swing using the scrollPane, so I can scroll an image in a box

    A very simple way is to use a JLabel :
    JLabel label = new JLabel(new ImageIcon("myImage.jpg"));
    JScrollPane scroller = new JScrollPane(label);

  • Month day display in matrix report

    in matrix report date field convert into day and it is as row filed if any day of month data not found but it display all 30 days in matrix report.

    try this query
    select rownum as run_num,to_date('01-' || :A_MONTH || '-' || :A_YEAR,'dd/mm/yyyy')+ (rownum-1) CV from
    (select 1 from dual group by cube (1,1,1,1,1))

  • How to display calculated matrix columns in a graph?

    Hi, 
    I am working in VisualStudio 2010 hitting SQL Server 2012 to build SSRS reports.
    I have a need to graph year over year percentage growth as derived from two SSRS matrix columns.  Everything is working except that the chart displays only one value for each year series, rather than displaying the correct percentages for each audience
    for each of the two years.
    The values in the chart series properties are called with the expression: =ReportItems!YoYGrowthPercent2014.Value (or =ReportItems!YoYGrowthPercent2014.Value, respectively), where "YoYGrowthPercent2014" is the name of the detail cell holding
    the expression to calculate the growth percentage at the audience level in the matrix.
    It looks like it should work yet the results are incorrect.  I've read several hundred articles and posts at this point and do not have an answer.
    Is there any way to do this? It seems like it should be so simple, and yet...
    Thank you!
    ~Khrys.

    I can reproduce your issue.  If you toggle open Audience P I think you will find the very last value for the last Category and the last Product_Group will be around 15% for Growth 2014 and around 23% for Growth 2015.  The chart series expression
    is choosing the last value for ReportItems!YoYGrowthPercentage as it doesn't know how to attribute that ReportItem to the Audience matrix.  If you want a chart to display only the percentage for Audience, I suggest that you have a separate data
    source with the values for GrowthPercentage for only the Audiences, and make that the data source for your chart. Also, I would make the growth figures in your matrix also a matrix by doing the percentage calculation directly in the table. You would pull in
    the value for this year and the value for last year into your data set, and then do the calculation within the report as follows:
    =SUM(Fields!Value.Value)/Sum(Fields!LastYearValue.Value)-1
    Create a second Column Group adjacent after, also by year.  Your query could look something like this, depending on how your tables are structured:
    SELECT a.Audience, a.Category, a.ProductGroup, a.Year, a.Value, b.Year as LastYear, ISNULL(b.Value,0) as LastYearValue
    FROM YoYGrowth a LEFT OUTER JOIN
    YoYGrowth b ON a.Audience = b.Audience and a.Category= b.Category and a.ProductGroup = b.ProductGroup
    AND a.Year-1 = b.Year
    Hope it helps.  Cheers,
    Martina White

  • Displaying large image in Swing 's Frame

    Hi,
    I'm new to java swings please let me know or sample code of how to display a complete large image in to a small container so that the image should be compressed and the complete image should be fitted into the container.
    Thanks in advance

    jameel wrote:
    please send me the sample working codeNo.
    Come on now. We are all volunteers here, and this is not a code-spitting factory. Search with Google, or search the forum, or create your own code. You are then welcome to present your own code here and ask questions about it, but you must do the brunt of the work here. Got it?

  • How to display console messages is Swing?

    HI all, I am developing an email client, and got everything right with the networking part and all...........but still got problem with displaying the retrieved mails
    I tried using the editpane....but can get it right......
    is there someway to fix.....i want to show HTML formatted mails too....show editpane is the right option i guess..
    someone help......

    well...it isn't just String i guess....like i said....emails is what i wanna display.....with HTML formatted text....
    I had tried to save the retrieved mail, after applying "Message.toString" to the retrieved mail...and tried to >display the file in JEditorPane.....but it didnt workout....
    and is there any way to use println in Swing? to display in GUI that is...... wow im really confused now but ill try my best to help.
    why is the email html formatted shouldnt it be just raw TEXT. or are you trying to get it from a web page itself.
    and what do you mean by: > and is there any way to use println in Swing? to display in GUI that is......
    println is similar to printing to a console. and GUI (graphical user interface) emphasis on the graphical, has nothing to do with println function. println can be used anywhere in your app to print out a objects contents.
    Lable or some other sort of GUI compnent should work for you
    thanks
    N

  • What component to display a matrix

    I want to create a grid with horizontal and vertical header, like Excel tables.
    All the cells of this grid are independant :
    seems to me that in a datagrid, the cells of a same row represent differents fields of a unique dataProvider element.
    but here I want that each cell represent an independant element.
    For example I would like to have a model that is a matrix, maybe an ArrayCollection of ArrayCollections, and each element of this matrix is displayed in the corresponding cell.
    What component would you use ?

    Here is the mxml part of my renderer (Labels are bound on var sound:XMLList that has only one XML element) :
    <s:Group>
         <s:states>
            <s:State id="noSound" name="noSound"/>
            <s:State id="soundRecording" name="soundRecording"/>
            <s:State id="soundRecorded" name="soundRecorded"/>
        </s:states>
        <s:Rect width="100%" height="100%" >
            <s:fill>
                <s:SolidColor id="background" color="0xFFFFFF"/>
            </s:fill>
            <s:stroke>
                <s:SolidColorStroke color="0x000000" weight="1"/>
            </s:stroke>
        </s:Rect>
        <s:Label x="5" y="5"
                 text="{sound.@id}"
                 includeInLayout="{isExpanded}" visible="{isExpanded}"/>
        <s:Label x="40" y="5"
                 includeIn="soundRecorded"
                 includeInLayout="{isExpanded}" visible="{isExpanded}"
                 text="{sound.@pathName}" toolTip="{sound.@pathName}"
                 width="100%" maxDisplayedLines="1"/>
        <s:TextArea id="descriTA" x="5" y="22"
                    includeInLayout="{isExpanded}" visible="{isExpanded}"
                    width="150" height="60"
                    change="{descriChange(descriTA.text)}" text="{sound.@descri}"/>
        <s:Image id="playImage" source="{SoundGrid.playIcon}"
                 mouseDown="{playImage.source = SoundGrid.playIconDown}"
                 mouseUp="{playImage.source = SoundGrid.playIcon}" mouseOut="{playImage.source = SoundGrid.playIcon}"
                 includeIn="soundRecorded"
                 includeInLayout="{isExpanded}" visible="{isExpanded}"
                 x="5" y="84"
                 toolTip="play"
                 click="playClicked()" />
        <s:Image id="recordImage" source="{SoundGrid.recordIcon}"
                 mouseDown="{recordImage.source = SoundGrid.recordIconDown}"
                 mouseUp="{recordImage.source = SoundGrid.recordIcon}" mouseOut="{recordImage.source = SoundGrid.recordIcon}"
                 includeIn="noSound"
                 includeInLayout="{isExpanded}" visible="{isExpanded}"
                 x="5" y="84"
                 toolTip="record"
                 click="recordClicked()"/>
        <s:Image id="stopImage" source="{SoundGrid.stopIcon}"
                 mouseDown="{stopImage.source = SoundGrid.stopIconDown}"
                 mouseUp="{stopImage.source = SoundGrid.stopIcon}" mouseOut="{stopImage.source = SoundGrid.stopIcon}"
                 includeIn="soundRecording"
                 includeInLayout="{isExpanded}" visible="{isExpanded}"
                 x="5" y="84"
                 toolTip="stop"
                 click="stopClicked()"/>
        <s:Image id="importImage" source="{SoundGrid.importIcon}"
                 mouseDown="{importImage.source = SoundGrid.importIconDown}"
                 mouseUp="{importImage.source = SoundGrid.importIcon}" mouseOut="{importImage.source = SoundGrid.importIcon}"
                 includeIn="noSound"
                 includeInLayout="{isExpanded}" visible="{isExpanded}"
                 x="50" y="84"
                 toolTip="import"
                 click="importClicked()"/>
    </s:Group>

  • Display powerpoint presentation in Swings

    hiii,
    I am developing an application in which i need to browse powerpoint presentation...and need to display in JFrames.For that i got a source that we have to use(import) org.apache.poi.hslf.HSLFSlideShow package,org.apache.poi.hslf.model.Slide; org.apache.poi.hslf.usermodel.SlideShow bla bla. but i dont know how to download and how to use those...Will anyone give an Hint how to solve

    Sorry, but your question isn't related to this forum, and it doesn't sound like a Swing question. It's more of a POI question. Try to ask it in the mailing list or forum for POI.
    Kaj

  • Display retreived mails in Swing ...

    How can I display the retreived mail headers and mails in a Swing window?
    Also...how to make the mail headers clickable?

    Most of this is a Swing question, not a JavaMail question, so you should try
    asking in the Swing forum, but... Did you find the example client application
    included with JavaMail? It's very primitive, but it might get you started.

  • How to display the time in Swing jtable

    I need to display the time in jTable.
    The time is a date field in ORACLE database (connected via
    Oracle Thin drivers).
    Im totally stuck. Please help.
    TIA.

    Thanks for your reply.
    My problem is that I have to display time. This time is a DATE field
    in ORACLE database.
    Im using FORTE (UI). What the jTable display is the DATE (1900-01-01) which is not what I want. I want the time to appear in the jTable (hh.mm.ss a).
    What I did was to use the TO_CHAR function of ORACLE to format the
    date to display the correct time in the VIEW before mapping this view
    to be used as a MODEL by the jTable.
    It works now.
    Much appreciate all your help. Thanks.

Maybe you are looking for

  • Can I transfer books from a PC to an ipad

    I don't have an ipad now but I am thinking about getting an ipad mini. I have a lot of books on my PC. Is it possible to transfer the books that are on my PC to my new ipad (if I get one) ?

  • BSP Error when copying text from email to Note section of a transaction

    Hi All, We are using CRM2007 for both the Interaction Centre and Sales Web Client. When a user is creating a transaction in both roles, if one copies a piece of text from an email into the note section of a transaction at times the web client crashes

  • Ipod Touch keeps crashing, now wont open at all.

    I got my ipod touch a little under a year ago, and soon after getting it i noticed that the music would randomly stop and go to the homepage. It wasn't that bad because the music would always come back up, and it didn't happen that often. But then it

  • Quicktime  videos play with no sound ,no video after 2013 uppdate

    i recently had the great idea to uppdate my phone and after backing up all my files to my IMAC. So now I cant 's watch my videos anymore. the videos play in quicktime  without sound and image- All the pictures are fine but the mov files are there but

  • Reverse animation/transition on event

    So I'm having a bit of issue getting an animation of mine to behave the way I want. My intent is to have an animation start on a button press (or any given event), play till its end, and then reverse once the button is released (which could happen in