BorderLayout right approach?

I asked a question wrt BorderLayout in the programming forum and was asked to post such questions here. Basically I have a JFrame and I want to put a JPanel in the middle of it. I tried using BorderLayout.CENTER but the default center behavior is to fill all available area. The person replying to my question stated that this behavior can not be disabled. If that is true what is the best layout manager option to put my panel in the middle and be the sole component added to the frame?
Is there such a creature as relative positioning where I specify where to stick my panel with no need to use a layout manager?

I searched some more and found this:
Using a horizontal box and a verticle box can do it.
import java.awt.BorderLayout;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Center extends JFrame {
public Center(){
Box xp = Box.createHorizontalBox();
xp.add(Box.createHorizontalGlue());
xp.add(new JButton("Center"));
xp.add(Box.createHorizontalGlue());
Box yp = Box.createVerticalBox();
yp.add(Box.createVerticalGlue());
yp.add(xp);
yp.add(Box.createVerticalGlue());
getContentPane().add(yp, BorderLayout.CENTER);
public static void main(String[] args) {
JFrame f = new Center();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(400, 400);
f.setVisible(true);
as part of the thread
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=609087.
dingjing is the creator of this code and many thanks!
I tweaked it a bit to fit into my program and it works like a charm! I will now shut down my Eclipse and research WHY it works!
Thanks for the suggestion! I will try that too and compare.

Similar Messages

  • Which one is the Right Approach - Re Using Page Layouts or adding Web parts directly to pages instead of page layouts in SP 2013 online site ?

    Hi Team,
    I am SharePoint 2013 developer. Before asking question I would like to explain the requirement in clarity.
    We are developing one O365 SharePoint online site which is having 10 different page layouts with different and some common webparts and we are reusing these page layouts by deploying a sandboxed solution which is having page layouts. These page layouts contain
    filter and query to display data using some condition and predefined values. By using these layouts we have to create 100+ pages. All pages will show data according to that page name and category (if it belongs any). We have not written any code to develop
    the site, everything is OOB feature.
    We have used below feature/list/lib of SP Online 2013:
    - Document Library
    - Survey
    - Calendar
    - Lists
    - Discussion forum library
    - OOB Search feature
    Now, I would like to know whether this is the right approach to reuse the page layouts. Or can we add webparts directly where the logic resides in the webparts and add them to the pages instead of page layouts?
    Also how to deploy page layouts/pages from one server to another? Currently we are deploying everything as a feature using sandbox solution. 
    Could you please let me know the right approach to follow. I am asking this question because we are facing below issues:
    - Sometime page layouts gets corrupted, showing nothing.
    - All written filters/logic disappear when we open layouts in Designer
    - Deployment is pain using Sandbox solution
    Waiting for your reply.
    Thanks in Advance,
    Shifa Mittal

    Interesting question, to which i do not know a definitive answer.
    Output Caching is used to increase performance and to reduce load on the box. However since you're in the MS Cloud you don't need to worry about the latter and MS do the worrying about the former. I wouldn't be surprised if MS have updated the behaviour
    for O365 and not updated the documentation. That first office.com article is using 2010 screenshots which doesn't fill me with confidence about it's continuing relevance. Don't forget that SharePoint 2013 and O365 are technically different versions and have
    very different behaviour in places.
    Generally i'd say not to worry, but in this case if you do find any more information i'd love to see it.

  • Right Approach for Applications & Projects

    Hi
    We do have a big application with many modules in it spanned across different teams. What's is the right approach for defining Applications ,Model and UI Projects ?Do we need to create applications for each module ? Or its better to use a single application and many Model and many UI projects on it ? Or many model projects and a single UI Project ? There can be dependency with other modules.
    Thanks
    Suneesh

    Sunesh,
    Lots of discussions on the ADF Enterprise Methodology Group on this topic:
    http://groups.google.com/group/adf-methodology/browse_thread/thread/e7c9d557ab03b1cb
    http://groups.google.com/group/adf-methodology/browse_thread/thread/bd0a6ec3255d8a7a#
    http://groups.google.com/group/adf-methodology/browse_thread/thread/01f4aced1f963061#
    http://groups.google.com/group/adf-methodology/browse_thread/thread/3347664e066fc44f#
    http://groups.google.com/group/adf-methodology/browse_thread/thread/ccfe981634569d38#
    http://groups.google.com/group/adf-methodology/browse_thread/thread/218f2f5f51a6f853#
    http://groups.google.com/group/adf-methodology/browse_thread/thread/0fbb4b8a267369de#
    John

  • The right approach to get pins/cells in deep hierarchy design.

    I always have hard time to get a pin or a cell in deep hierarchy. E.g. I have module "A", I instatiaed it as "a_inst", inside it has a submodule B, inside B I has a submodule C, I also instantiated them as "b_inst", "c_inst". Then I try to get a pin from C for my constrain like "get_pins a_inst/b_inst/c_inst/D". But in some cases, I can't get it.
    This problem is especially worse when I try to get pins from a Xilinx IP. Somethimes, I try to follow the hierarchy path but Vivado always report there is no that pin or cell. 
    I just wonder what is the right approach to get pins/cells in deep hierarchy module? Is there any standard approach that will work for all (at least most) cases?
    Thanks very much.

    The "best" way is to do what you described, but do it right... If the hierarchy isn't flattened, then the full hierarchical path to a pin is consistently named as a_inst/b_inst/c_inst/D.
    In Vivado, it is important to note, though, that the pin's name is not a_inst/b_inst/c_inst/D. Vivado is aware of the hierarchy, and the hierarchy is real. The pin name is actually "c_inst/D", inside the hierarchical object b_inst, which is inside the hierarchical object a_inst (assuming hierarchy hasn't been flattened). So the / means two separate things; the final / is a character - part of the name c_inst/D. The other / are hierarchy separations, which are not characters.
    This is important to understand for wildcarding... This pin will NOT be captured by [get_pins *c_inst/d], since the slashes before c_inst are not characters. It would be matched by [get_pins */*/c_inst/d], since that is saying "look for c_inst/d two levels of hierarchy down".  However, since the last / is a character [get_cells a_inst/b_inst/c_in*d] would match it.
    You could also use [get_pins -hier c_inst/d]; this means look for a net named c_inst/d anwhere in the hierarchy. But this is sloppy, since there may be other things named c_inst/d somewhere else in the hierarchy. You cannot, however, mix the -hier option with a partial hierarchical path; for example [get_nets -hier b_inst/c_inst/d] will not work.
    It is important to note that this is very different from how UCF worked. In UCF, the hierachy separator was just a character, and you could use PIN *c_inst/D to match the pin anywhere in the hierarchy, since the * would match "a_inst/b_inst/". You can (but should try to avoid) mimic this behaviour by using the -filter option 
    [get_pins -filter {NAME =~ *c_inst/D}]
    will match your pin in a UCF like style - but, this should be avoided.
    Note: If hierarchy is flattened, the rules change. If hierarchy is rebuilt, then this should work, but I don't trust it (which is why I always use flatten_hierarchy set to none).
    As for IP, you shouldn't reach down into Xilinx IP. From version to version of the core, the structure can change - so the hierarchical path could change. I am not sure why you would need to do this; you should restrict yourself to using the pins of the IP (and use things like all_fanin and all_fanout if you need to get to the startpoint/endpoint of static timing paths that start/end in the IP).
    Avrum

  • Reverse database mirroring - and is this the right approach?

    Here is my scenario. I have 2 database servers, P and M, to serve our production website. P = Principal; M = Mirror.
    After some time my Principal crashes. No problem, I've got M, it's been synchronizing, and it has all latest data. So I repoint my production web server to hit the Mirror. Still, all is good.
    Now comes the part where I'm fuzzy, and I need to know if my understanding is correct...
    The Principal comes back online, but my website is still pointing at the Mirror. I want to repoint the site back to Principal. But P now has old data. Maybe it's been down 3 days and M has 100,000 new records that don't exist in P. When P came back online,
    did transaction logs begin shipping from M to P to get P back in sync? Would it do that if a Witness were in place? How does P get caught up with all latest data? Do I have to do a full backup and restore from M to P? Is there a way this can be set up to just
    gracefully (or even easy manual) get P updated and synced? Can the Principal/Mirror roles be easily swapped between the 2 servers? Does that happen automatically with a Witness in place?
    Thanks in advance for any help.

    First, mirroring is being removed for "AlwaysOn" technology.  I would not recommend using it in SQL 2012.  However, if you are talking about prior versions, then...
    When the failover occurs, the old mirror, now primary, attempts to send updates back to the old principal, now mirror.  This is completely automatic and requires nothing manual to happen.
    However, if the now mirror is down for a long period of time, the transaction log on the principal will continue to grow and grow until it is able to deliver the transactions to the mirror.
    You can setup your website with a "Failover Partner=" in the connection string and the failover/failback will be completely invisible to your application.
    I would suggest reading:
    http://technet.microsoft.com/en-us/library/ms189852.aspx
    http://technet.microsoft.com/en-us/library/cc917713.aspx

  • Are sequence structures the right approach here?

    Hi everyone,
    The attached VI shows the endmembers in case structure form of a relatively simple task I need to perform.  It takes a bank of 6 digital outputs and toggles between true and false logic.  Between the endmembers, I need to change the logic on some ports sequentially and after time delays.  For instance, changing the case from true false, I need to change line 2 from false to true 2 seconds before I change lines 4 and 5 to true.  I want the user to see only one button to toggle between states, and I want the states to be discrete and not continuously changing.
    Are sequence structures the best way to do this?  If I put those into the case structure, won't it re-iterate the sequence over and over?  Or do I need a case structure initialized with shift registers so that it stops after one interation until the next time the user toggles the control?
    Thanks for any help on this,
    Brad
    Attachments:
    ValveBankEndMembers.vi ‏56 KB

    I have a couple suggestions.  Most important, have two cases in your case structure.  One for the toggle, one for the quit.  Otherwise you will have to wait for a toggle in order to process the quit.  I also lumped the controls into a cluster.  You are converting from array to cluster anyway, this saves you the unbundle.  Finally, since you are toggling each boolean, you can just apply a NOT to the entire array and use a shift register to pass the array from one loop iteration to the other.  This last will save a lot of debugging headaches if you ever need to add/remove bolleans.
    Message Edited by jasonhill on 06-14-2006 09:05 AM
    Attachments:
    Toggle Trap 2.PNG ‏14 KB
    ValveBankEndMembersEvent2.vi ‏16 KB

  • 11.2.0.3 Patch Bundle and opatch installation approach

    Hi,
    I have installed the below 11.2.0.3 (64 bit) products in my windows 2008 server
    1. Oracle Grid Infrastructure for standalone server
    2. Oracle database server software and created a standalone database with ASM in this home.
    Now i need to apply Update 5 patch bundle and some bug fix patches.
    Since there are 2 home in my server what is the right approach for applying the patch bundle and opatch ?
    When i went through the patch bundle installation document i could see these 2 options
    1. Patch Installation Instructions for Single Instance
    2. Patch Installation Instructions for RAC
    Since i have 2 homes (OraCrs11g_home1 & OracDb11g_home1 ) in my server i am not sure which patch installation option i should choose and proceed.
    Can someone assist me ?
    Thanks,
    Ashok Kumar.G

    no we have to prepare a test POC but we don't have Xterm so had to use silent mode.using VNC server is best option to install or upgrade databases/grid Infrastructure.
    VNC server runs on the server and no fear of loosing network connection as in case of connecting thorugh putty.
    also you can open GUI in VNC server without need of any xterm or xwindows .
    So ask your SA to install VNC on your server and use it.

  • Approach on Cost Center for Vehicles

    Hi Experts,
    I have a requirement to analyze the cost and profit of the vehicles internally. These vehicles can be assigned from one plant to another every month. Right now the setup for cost centers is grouped by the company site only. What is the best approach on this requirement?
    I have listed some solution and one of the approach was to create cost centers for each vehicle. So for each vehicle counting at around 200 should be maintained in the cost center hierarchy. Is this the best possible solution?
    Also what about the Report that shows the cost center vehicles profit and loss? it should show under a specific cost center group but because of the behavior of the vehicle cost center, every time the vehicle cost center is reassigned to another cost center group, it should also show in the report that it has been maintained in the right cost center in that duration. So the report will reflect the cost center under cost center group A, example last month and another cost center group B, this month.
    Also I am considering Profit Center but I am not familiar with the idea.
    Please help on this solution. Thank you so much.

    Hi
    1. I am not sure how your vehicles are going to earn revenue.. From your question, I assume yours is a mfg concern, then how and why does the profitability of vehicles is important for your business, unless yours is a transport business.. Correct my understanding, incase wrong
    2. Cost centers (CC) would not be the right approach... You cant post revenues in a cost center... They can be posted only statistically in a CC
    3. Use Internal Orders (IO).. In IO Type (T Code KOT2_OPA), allow for revenue postings as well.
    4.
    a. Your numbering of the IOs can be same as vehicle no for the sake of simplicity.
    b. Or Else, you can capture your vehicle no in any of the free fields and create a New Search (F4) help based on this field in T code OKO1...
    c. Or Else, you can create new fields for IO to capture Vehicle no, include them in Structure CI_AUFK. For this use exit COOPA003
    5. Once you post your costs and revenues in IOs, you can derive prof reports either from standard IO reports or create a new one using report painter
    6. Now Coming to your question of identifying the vehicles under plants in which they were under a certain period - I would suggest to drop this requirement. However, if you still want to have it, then maintain a Z table in which you have fields like IO, Plant, Dates From and To. Based on this info, you need to create an ABAP report
    Regards
    Ajay M

  • Best approach for syndication in Central MDM

    MDM 7.1
    CE 7.2
    ERP 6 EHP4
    PI 7.1 EHP1
    We are currently developing a custom application using CE/BPM workflow for central maintenance of customer master data. One of the topics under discussion is the right approach for syndication once a record is complete.
    [This |http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/60a3118e-3c3e-2d10-d899-ddd0b963beba?quicklink=downloads&overridelayout=true] SAP document on collaborative material master data creation provides one way to achieve this syndication by first calling a web service from BPM to create record in ERP before checking in MDM. While I am personally fine with the approach, some of the other colleagues aren't too keen on issuing synchronous calls from BPM. Rather, they would like to use the syndication engine of MDM to transmit data to downstream systems (currently only SAP ERP) using Idocs. But there is a caveat here. To use syndication, the record has to be checked in.
    The problem is that if the record is checked in MDM, it is ready for modification. However, the asynchronous call to ERP using Idocs for creation of customer master might fail for any number of reasons. In this case, the MDM record might need a modification before resubmitting to ERP. In the meantime, since the record was checked in before syndication, someone else might have checked it out, potentially resulting in data quality issues. So to avoid this situation, the developer has decided to take the approach to check in -> syndicate -> check out -> wait for confirmation Idoc -> check in if success. This isn't a clean approach to syndicate but might address the record locking issue.
    Another consideration is to design the application with the view that sometime in the future, this master data might have to be syndicated to other SAP and non-SAP systems as well. To ensure syndication to all downstream systems is complete before checking in MDM can be a tricky requirement and might need some complex ccBPM development or evaluating something similar to two-phase commit (might be an overkill). In any case, a best practice approach for keeping downstreams systems in sync with MDM in case of central MDM has to be shared by SAP. So it would be good to have comments of the people who developed the reference application for collaborative material master data creation.
    If there are any customers who have come up with a custom solution which works, please do share the experience.
    Thanks and regards,
    Shehryar

    Thanks Ravi. While there are more than one possible solutions to the immediated problem, I am actually looking for a design pattern which SAP recommends or a customer has developed to address the issues related to synchronization of master data in a Central MDM environment.
    The idea behind a central master data management function, as you know, is that all participating business systems use the same basic master data being authored in MDM. This data has to be synchronized with all participating systems, rather than just one system. To me, a ccBPM workflow or 2 phase commit design pattern seem to be the solution. But it would be good to know how other customers are addressing the issue of master data synchronization with multiple systems, or SAP's recommendations for this issue.
    Regards,
    Shehryar

  • Best approach to store collection for html:options

    I am using struts to develop my web application. I am trying to figure out the best way to store a Collection for html:options inside a html:select element.
    My JSP page has a html:select statement which lists all the groups in a system. I have a member variable called getGroupNames() in my ActionForm class. When the JSP page is first requested, I populate the groupNames attribute of ActionForm class with a list of names. The html:options reads the groupNames attribute and lists all the group names.
    The problem: Once the user selects a group name and then submits, if there is any validation problems in other fields in the JSP, I build ActionErrors object and forward the request back to the same JSP. However, now I get an error saying the groupNames is NULL.
    Option1: One way to avoid this error is to AGAIN populate the groupNames list if there is a validation problem.
    Option 2: Another way is to store the list of groupnames in a seperate bean (and NOT as an attrib of the ActionForm) and store it in the REQUEST scope. This way I think the I don't have reload the groupName list in case of a validation failure.
    Could someone please help me in deciding which will be the right approach.
    Thanks

    Hi,
    1,2 billion rows and each row of 50 bytes - approximately 56 GB around. Huge segment. As you stated it's an OLTP database, can you check across what is the percentage or maximum number of queries with developers - important column which they are querying across and application dealt with.
    Based on the input of the above question we can check how best we can partition and columns we are dealing. Perhaps you have stated across historical data. From this kindly verify across what is the % of users check or go-back to historical information - based on that we can estimate the number of partitions we can create on segment and looking forward, you must estimate the % of increase of new/incoming data and day/month wise. so that you might be plan what can we do the old historical data.
    HTH
    Note- Part of Performance dealt with writing efficient tuned queries
    - Pavan Kumar N

  • Best Approach for Security in WebCenter Portal Application

    Hi,
    We are analyzing a right approach for webcenter portal security on an application . We found that we can do all Roles and Security in Page Hierarchy which in turn stores the security details in Jazn-data.xml . Is this the right approach for defining the roles and security for a webcenter portal application .
    What is the importance of Configuring WS_security in webcenter Portal Application and do we need to define this WS_Security even after defining them in page hierarchy. Could you please guide us on this .
    Thank you,
    Sashank P

    Hi Shashank,
    First sorry for late reply,
    WS_Security, can you please explain what do you mean by WS_Security, from the term i could not infer which part you are talking about.
    Let me tell you about the Webcenter security -
    This is the heirarchy , the Fusion middelware forms the base with webcenter at the top.\
    Webcenter Security
    |
    ADF Security
    |
    Fustion Midddleware Security (OPSS)
    Now you are goin to apply security to your Webcenter and ADF layers.
    Lets come back to the question .
    Any webcenter portal, you have to use the Jazn-Data.xml file to secure all the content whether its the navigation /pages /admin pages/taskflows etc.
    Its pretty much easy to use , let me know if you have any difficulty on that.
    Page hierarchy -> Yes you have an option to set your security for pages alone, here you have addition fine grain permisions (update/delete/personalise etc).
    If you need those fine grain permissions you can use this.
    To Conclude i would say use jazn-data for taskflows/components/admin page protection etc.
    Use Page heirarchy's fine grain permission to pages and navigation model's visible attribute to show/hide navigation based on user's roles.
    Let me know if this helps

  • Approach for O365 mails (pros and cons of both)

    Hi Team - What is the right approach to access seamless, flawless emails of O365 in our laptops having Mavericks OS and MailMail . Is Office 2011 for MAC the right choice or should we stick to native MailMail for O365 mails (pros and cons of both).
    We attempted with native messaging client but are facing lots of issues related to synchronization, delay, missouts etc...  & we are not sure if we shift our users to Office 2011 for MAC, that will fix up the issues.
    Please advise..
    Best regards,

    Database Register in two way :
    1.) Static Instance Registration
    2.) Dynamic Instance Registration
    ** Static Instance Registration:
    add the entries in $ORACLE_HOME\NETWORK\ADMIN\listener.ora file or by using the GUI
    LISTENER =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx)(PORT = 1521))
      )When you check Listener status --> unknown because no mechanism to guarantee that the specified status even exists.
    **Dynamic Instance Registration
    or service registration , registration is performed by the PMON process an instance background process of each database and doesn't need any configuration in the listener.ora
    Read
    http://docs.oracle.com/cd/B28359_01/network.111/b28317/listener.htm

  • Fragment size setting approach

    Hi,
    I am trying to use fragment as header and on its right-hand upper corner, I want to put Login/Logout hyperlink. I am facing problem in fragment's size, the header fragment should cover whole browser, irrespective of browser window�s size, desktop pixel resolution. And this hyperlink should be visible when user resizes the window. I guess this normally happens in any standard web site. I tried setting width pixels say 720 or setting width to 100%, but didn't work, the link doesn't appear at end.
    Any suggestions regarding this?
    More or less the same issue, I am also thinking to use another fragment (not sure if it right approach) at vertical right hand side, something like to show google ads, what settings should I do, so that this vertical fragment should appears in right end side of browser window?
    So basically, I am thinking to use four fragments for all pages i.e. header, footer, left and right.
    Any help will be greatly appreciated.
    Thanks.

    Found few pointers
    http://blogs.sun.com/roller/page/winston?entry=css_layout
    http://blogs.sun.com/roller/page/winston?entry=template_creation
    http://forum.sun.com/jive/thread.jspa?forumID=123&threadID=50947

  • Change fields via field.set

    I don't quite know if this is the right approach for the problem, but I hope, anyone can make that clear to me:
    I got two Applications called "app1" and "app2". app2 is a simple swing-application which, to make it simpler, only consists of a JTextField (pseudocode following).
    JTextField vlaue_1 = new JTextField("test");
    ...The application app1 now starts app2 (using Class.forName and Method.invoke). Then, it gets all of app2's fields, in this case value_1, via getDeclaredFields.
    import java.lang.reflect.Field;
    import java.lang.reflect.Method;
    public class app1 {
         public app1() {
              super();
           public static void main(String[] args) throws Exception {
                Class testClass = Class.forName("app2");
                Method mainMethod = findMainMethod(testClass, "main");
                mainMethod.invoke(null, new Object[] { String[] arguments });
                Field[] fields = testClass.getDeclaredFields();
         private static Method findMainMethod(Class clazz) throws Exception {
              Method[] methods = clazz.getMethods();
              for(int i = 0; i < methods.length; i++){
                   if(methods.getName().equals(name))
                        return methods[i];
              return null;
    Now, app1 knows about the TextField in app2.
    And finally, the question is: Can I change the String in app2's value_1 into something different out of app1? For example, app1 says "Hey TextField, you are no 'test' any longer, you are now a 'foo'" and app2 updates its swing-GUI instantly?
    I already tried a field.set(Obj arg1, Obj arg2) and got only exceptions, but probably because I don't quite know which objects are meant for arg1 and arg2.
    Perhaps someone has some (pseudo-)code to clarify this issue.
    Any help would be nice. Thanks

    Ok, the original code for app2 is the following (the app doesn't make much sense, was only created for testing this issue):
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class TestApp extends JFrame implements ActionListener{
         public static JTextField wert1 = new JTextField("15");
         public static JTextField wert2 = new JTextField("12");
         public static JLabel ergebnis = new JLabel("0");
         public static JButton berechnen = new JButton("Berechnen");
         public TestApp() {
              JFrame frame = new JFrame("TestApp");
              JPanel north = new JPanel();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.getContentPane().add(north, BorderLayout.NORTH);
              north.add(wert1, BorderLayout.CENTER);
              north.add(wert2, BorderLayout.CENTER);
              frame.getContentPane().add(ergebnis, BorderLayout.CENTER);
              frame.getContentPane().add(berechnen, BorderLayout.SOUTH);
              berechnen.addActionListener(this);
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              TestApp gui = new TestApp();
         public void actionPerformed(ActionEvent event) {
              double ergebnis_1;
              double wert_1 = Double.parseDouble(wert1.getText());
              double wert_2 = Double.parseDouble(wert2.getText());
                  ergebnis_1 = wert_1 + wert_2;
                  ergebnis.setText(Double.toString(ergebnis_1));
    }The code for app1 follows here:
    import java.lang.reflect.Field;
    import java.lang.reflect.Method;
    public class JavaTester {
         public JavaTester() {
              super();
         public static void main(String[] args) throws Exception {
              Class testKlasse = Class.forName(args[0]);
              String[] neueArgs = uebergebeArgs(args);
              Method mainMethode = findeMethode(testKlasse, "main");
              mainMethode.invoke(null, new Object[] { neueArgs });
              Field[] felder = testKlasse.getDeclaredFields();
         private static String[] uebergebeArgs(String[] args) {
              String[] rueckgabe = new String[args.length - 1];
              for(int i=1; i<args.length; i++) {
                   rueckgabe[i-1] = args.toLowerCase();
              return rueckgabe;
         private static Method findeMethode(Class klasse, String name) throws Exception {
              Method[] methoden = klasse.getMethods();
              for(int i = 0; i < methoden.length; i++){
                   if(methoden[i].getName().equals(name))
                        return methoden[i];
              return null;
    I'm sorry that I can't print the stacktrace, because I just don't know, how to call the field.set function.
    Is it for e.g. felder[0].set(???, ???)?

  • Edit menu - allowing copy/cut/paste

    I am working on creating an edit menu and I would like to be able to disable the copy/cut/paste items in the menu when their use is not possible (like when there is no text based field to copy from).
    I am guessing that one approach I can take is as follows:
    1) Determine what component currently has focus, and whether it is a text field. If it is not a text field, then all three of the menu items should be disabled.
    2) If it is a text field and there is a selection, enable the copy and cut menu items.
    3) If it is a text field and there is an insertion point, then enable paste.
    However, I have no idea how to accomplish any of those three step. Or even if that is the right approach. Also, I would like to implement the listener within my edit menu class itself (a subclass of JMenu), since I use it to insert edit menues into a number of different JFrames. I would appreciate any help or direction. Thanks.

    Woops! I see you want multiple windows. Here a redo with a frame & a dialog
    import java.awt.*;
    import java.beans.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class PasteAction extends AbstractAction {
        public PasteAction(final Window window) {
            super("Paste");
            setEnabled(false);
            putValue(MNEMONIC_KEY, new Integer('P'));
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_DOWN_MASK));
            putValue(SHORT_DESCRIPTION, "blah blah");
            //putValue(SMALL_ICON, icon);
            KeyboardFocusManager man = KeyboardFocusManager.getCurrentKeyboardFocusManager();
            man.addPropertyChangeListener("permanentFocusOwner",
                new PropertyChangeListener(){
                    public void propertyChange(PropertyChangeEvent evt) {
                        KeyboardFocusManager man = (KeyboardFocusManager) evt.getSource();
                        if (window.equals(man.getFocusedWindow())) {
                            Component comp = man.getPermanentFocusOwner();
                            setEnabled(comp instanceof JTextComponent);
        public void actionPerformed(ActionEvent e) {
            Component comp = getFocusedComponent();
            if (comp instanceof JTextComponent)
                ((JTextComponent)comp).paste();
        public static Component getFocusedComponent() {
            KeyboardFocusManager man = KeyboardFocusManager.getCurrentKeyboardFocusManager();
            return man.getPermanentFocusOwner();
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class ActionTest {
        public static void main(String[] args) {
            JFrame f = new JFrame("ActionTest");
            createContent(f);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.pack();
            f.setLocation(0,0);
            f.show();
            JDialog d = new JDialog(f, "dialog");
            createContent(d);
            d.pack();
            d.setLocation(f.getWidth(),0);
            d.show();
        static void createPanel(RootPaneContainer rpc) {
            Container panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.fill = GridBagConstraints.HORIZONTAL;
            for(int y=0; y<10; ++y) {
                gbc.gridy = y;
                gbc.gridx = 0;
                panel.add(new JTextField("field " + y, 20), gbc);
                gbc.gridx = 1;
                panel.add(new JButton("button " + y), gbc);
            rpc.getContentPane().add(panel);
        static void createMenuBar(RootPaneContainer rpc, Action action) {
            JMenuBar mb = new JMenuBar();
            JMenu menu = new JMenu("Edit");
            menu.setMnemonic('E');
            menu.add(action);
            mb.add(menu);
            rpc.getRootPane().setJMenuBar(mb);
        static void createToolBar(RootPaneContainer rpc, Action action) {
            JToolBar tb = new JToolBar();
            tb.add(action);
            rpc.getContentPane().add(tb, BorderLayout.NORTH);
        static void createContent(RootPaneContainer rpc) {
            createPanel(rpc);
            PasteAction paste = new PasteAction((Window)rpc);
            createMenuBar(rpc, paste);
            createToolBar(rpc, paste);
    }

Maybe you are looking for